1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/*
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using ShiftOS.Objects.ShiftFS;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static ShiftOS.Objects.ShiftFS.Utils;
using Newtonsoft.Json;
using ShiftOS.Engine;
namespace ShiftOS.WinForms.Applications
{
[Launcher("File Skimmer", true, "al_file_skimmer", "Utilities")]
[RequiresUpgrade("file_skimmer")]
[WinOpen("file_skimmer")]
[DefaultTitle("File Skimmer")]
[DefaultIcon("iconFileSkimmer")]
public partial class FileSkimmer : UserControl, IShiftOSWindow
{
public FileSkimmer()
{
InitializeComponent();
this.Load += (o, a) =>
{
ChangeDirectory(Paths.GetPath("root"));
};
}
private void lvitems_DoubleClick(object sender, EventArgs e)
{
if (lvitems.SelectedItems.Count <= 0)
return;
var item = lvitems.SelectedItems[0];
var path = item.Tag as string;
if(currentdir == "__system")
{
ChangeDirectory(path);
}
else if(DirectoryExists(currentdir + "/" + path))
{
ChangeDirectory(currentdir + "/" + path);
}
else if(FileExists(currentdir + "/" + path))
{
FileSkimmerBackend.OpenFile(currentdir + "/" + path);
}
else if(path == "__..")
{
ChangeToParent();
}
}
[Obsolete("This just forwards over to FileSkimmerBackend.OpenFile().")]
public void Open(string path)
{
FileSkimmerBackend.OpenFile(path);
}
[Obsolete("Forwarded to FileSkimmerBackend.GetFileType().")]
public static FileType GetFileType(string path)
{
return FileSkimmerBackend.GetFileType(path);
}
string currentdrive = "0:";
public void ChangeToParent()
{
if(currentdir == currentdrive)
{
ChangeDirectory("__system");
}
ChangeDirectory(GetParent(currentdir));
}
public string GetParent(string path)
{
string[] pathlist = path.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
if(pathlist.Length > 1)
{
if(path.EndsWith("/"))
{
path = path.Remove(path.Length - 1, 1);
}
path = path.Remove(path.LastIndexOf('/'), path.Length - path.LastIndexOf('/'));
return path;
}
else
{
return "__system";
}
}
private string currentdir = "";
public void ChangeDirectory(string path)
{
currentdir = path;
lbcurrentfolder.Text = currentdir;
ResetList();
}
public static void GetAllTypes(ImageList list)
{
list.Images.Add("Directory", Properties.Resources.fileicon0);
list.Images.Add("UpOne", Properties.Resources.fileicon5);
list.Images.Add("Mount", Properties.Resources.FloppyDriveIcon);
foreach (FileType value in Enum.GetValues(typeof(FileType)))
{
list.Images.Add(value.ToString(), GetImage(value));
}
}
public void ResetList()
{
if(lvitems.LargeImageList == null)
{
lvitems.LargeImageList = new ImageList();
lvitems.LargeImageList.TransparentColor = SkinEngine.LoadedSkin.ControlColor;
lvitems.LargeImageList.ImageSize = new Size(42, 42);
GetAllTypes(lvitems.LargeImageList);
}
lvitems.Items.Clear();
if (currentdir == "__system")
{
//List all drives
foreach (var dir in Mounts)
{
var item = ConstructItemAsMount(dir);
item.ImageKey = "Mount";
lvitems.Items.Add(item);
}
}
else if (DirectoryExists(currentdir))
{
var up = new ListViewItem();
up.Text = "Up one";
up.ImageKey = "UpOne";
up.Tag = "__..";
lvitems.Items.Add(up);
foreach(var dir in GetDirectories(currentdir))
{
var item = ConstructItem(GetDirectoryInfo(dir));
item.ImageKey = "Directory";
lvitems.Items.Add(item);
}
foreach (var dir in GetFiles(currentdir))
{
var item = ConstructItem(GetFileInfo(dir));
item.ImageKey = FileSkimmerBackend.GetFileType(dir).ToString();
lvitems.Items.Add(item);
}
}
}
public static ListViewItem ConstructItemAsMount(Directory dir)
{
var item = new ListViewItem();
item.Text = dir.Name + "(" + Mounts.IndexOf(dir).ToString() + ":/)";
item.Tag = Mounts.IndexOf(dir).ToString() + ":";
return item;
}
public static ListViewItem ConstructItem(Directory dir)
{
var item = new ListViewItem();
item.Text = dir.Name;
item.Tag = item.Text;
return item;
}
public static ListViewItem ConstructItem(File dir)
{
var item = new ListViewItem();
item.Text = dir.Name;
item.ImageKey = "Directory";
item.Tag = item.Text;
return item;
}
public static Image GetImage(FileType type)
{
switch(type)
{
case FileType.Executable:
case FileType.Lua:
case FileType.Python:
return Properties.Resources.fileiconsaa;
case FileType.Image:
return Properties.Resources.fileicon3;
case FileType.Skin:
return Properties.Resources.fileicon10;
case FileType.TextFile:
return Properties.Resources.fileicon2;
default:
return Properties.Resources.fileicon1;
}
}
private void FileSkimmer_Load(object sender, EventArgs e) {
}
public void OnLoad()
{
}
public void OnSkinLoad()
{
}
public bool OnUnload()
{
return true;
}
public void OnUpgrade()
{
}
private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
Infobox.PromptText("New Folder", "Please type a name for your folder.", (path) =>
{
if (!string.IsNullOrWhiteSpace(path))
{
if(!Utils.DirectoryExists(this.currentdir + "/" + path))
{
Utils.CreateDirectory(currentdir + "/" + path);
this.ResetList();
}
else
{
Infobox.Show("New folder", "A folder with that name already exists.");
}
}
else
{
Infobox.Show("New folder", "You can't create a folder with no name!");
}
});
}
}
}
|