BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Classes | Public Types | Static Public Member Functions | List of all members
BrawlLib.BrawlManagerLib.FileOperations Class Reference

A modification of David Amenta's RecycleBin code More...

Public Types

enum  FileOperationFlags : ushort
 Possible flags for the SHFileOperation method. More...
 
enum  FileOperationType : uint
 File Operation Function Type for SHFileOperation More...
 

Static Public Member Functions

static bool Copy (string path1, string path2, bool deleteFirst=false, bool confirmOverwrite=true)
 
static bool Rename (string path1, string path2)
 
static bool Delete (string path, FileOperationFlags flags)
 Send file to recycle bin More...
 
static bool Delete (string path)
 Send file to recycle bin; display warning if files are too big to fit (FOF_WANTNUKEWARNING) More...
 
static string SanitizeFilename (string filename)
 

Detailed Description

A modification of David Amenta's RecycleBin code

Member Enumeration Documentation

◆ FileOperationFlags

Possible flags for the SHFileOperation method.

75 {
82 FOF_ALLOWUNDO = 0x0040,
83
87 FOF_FILESONLY = 0x0080,
88
92 FOF_NOCONFIRMATION = 0x0010,
93
97 FOF_NOCONFIRMMKDIR = 0x0200,
98
102 FOF_NO_CONNECTED_ELEMENTS = 0x2000,
103
107 FOF_NOCOPYSECURITYATTRIBS = 0x0800,
108
112 FOF_NOERRORUI = 0x0400,
113
117 FOF_NORECURSION = 0x1000,
118
122 FOF_RENAMEONCOLLISION = 0x0008,
123
127 FOF_SILENT = 0x0004,
128
132 FOF_WANTNUKEWARNING = 0x4000
133
134 /* /// <summary>
137 FOFX_ADDUNDORECORD = 0x20000000,
141 FOFX_NOSKIPJUNCTIONS = 0x00010000,
145 FOFX_PREFERHARDLINK = 0x00020000,
149 FOFX_SHOWELEVATIONPROMPT = 0x00040000,
153 FOFX_EARLYFAILURE = 0x00100000,
157 FOFX_PRESERVEFILEEXTENSIONS = 0x00200000,
161 FOFX_KEEPNEWERFILE = 0x00400000,
165 FOFX_NOCOPYHOOKS = 0x00800000,
169 FOFX_NOMINIMIZEBOX = 0x01000000,
173 FOFX_MOVEACLSACROSSVOLUMES = 0x02000000,
177 FOFX_DONTDISPLAYSOURCEPATH = 0x04000000,
181 FOFX_DONTDISPLAYDESTPATH = 0x08000000,
185 FOFX_RECYCLEONDELETE = 0x00080000,
189 FOFX_REQUIREELEVATION = 0x10000000,
193 FOFX_COPYASDOWNLOAD = 0x40000000,
197 FOFX_DONTDISPLAYLOCATIONS = 0x80000000,*/
198 }

◆ FileOperationType

File Operation Function Type for SHFileOperation

204 {
208 FO_MOVE = 0x0001,
209
213 FO_COPY = 0x0002,
214
218 FO_DELETE = 0x0003,
219
223 FO_RENAME = 0x0004
224 }

Member Function Documentation

◆ Copy()

static bool BrawlLib.BrawlManagerLib.FileOperations.Copy ( string  path1,
string  path2,
bool  deleteFirst = false,
bool  confirmOverwrite = true 
)
inlinestatic
14 {
15 if (File.Exists(path2) && confirmOverwrite)
16 {
17 using (CopyDialog dialog = new CopyDialog(path2, path1) {Text = "Copy"})
18 {
19 DialogResult r = dialog.ShowDialog();
20 if (r != DialogResult.Yes)
21 {
22 return false;
23 }
24 }
25 }
26
27 string dir = Path.GetDirectoryName(path2);
28 if (!Directory.Exists(dir))
29 {
30 Directory.CreateDirectory(dir);
31 }
32
33 if (deleteFirst)
34 {
35 File.Delete(path2);
36 }
37
38 File.Copy(path1, path2, true);
39 return true;
40 }

◆ Delete() [1/2]

static bool BrawlLib.BrawlManagerLib.FileOperations.Delete ( string  path)
inlinestatic

Send file to recycle bin; display warning if files are too big to fit (FOF_WANTNUKEWARNING)

Parameters
pathLocation of directory or file to recycle
310 {
311 return Delete(path, FileOperationFlags.FOF_WANTNUKEWARNING);
312 }
static bool Delete(string path, FileOperationFlags flags)
Send file to recycle bin
Definition: FileOperations.cs:274
FileOperationFlags
Possible flags for the SHFileOperation method.
Definition: FileOperations.cs:75

◆ Delete() [2/2]

static bool BrawlLib.BrawlManagerLib.FileOperations.Delete ( string  path,
FileOperationFlags  flags 
)
inlinestatic

Send file to recycle bin

Parameters
pathLocation of directory or file to recycle
flagsFileOperationFlags to add in addition to FOF_ALLOWUNDO
275 {
276 try
277 {
278 if (IsWOW64Process())
279 {
280 SHFILEOPSTRUCT_x64 fs = new SHFILEOPSTRUCT_x64();
281 fs.wFunc = FileOperationType.FO_DELETE;
282 // important to double-terminate the string.
283 fs.pFrom = path + '\0' + '\0';
284 fs.fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags;
285 SHFileOperation_x64(ref fs);
286 }
287 else
288 {
289 SHFILEOPSTRUCT_x86 fs = new SHFILEOPSTRUCT_x86();
290 fs.wFunc = FileOperationType.FO_DELETE;
291 // important to double-terminate the string.
292 fs.pFrom = path + '\0' + '\0';
293 fs.fFlags = FileOperationFlags.FOF_ALLOWUNDO | flags;
294 SHFileOperation_x86(ref fs);
295 }
296
297 return true;
298 }
299 catch
300 {
301 return false;
302 }
303 }
FileOperationType
File Operation Function Type for SHFileOperation
Definition: FileOperations.cs:204

◆ Rename()

static bool BrawlLib.BrawlManagerLib.FileOperations.Rename ( string  path1,
string  path2 
)
inlinestatic
43 {
44 if (string.Equals(path1, path2, StringComparison.InvariantCultureIgnoreCase))
45 {
46 return true;
47 }
48
49 if (File.Exists(path2))
50 {
51 using (CopyDialog dialog = new CopyDialog(path2, path1) {Text = "Move"})
52 {
53 DialogResult r = dialog.ShowDialog();
54 if (r == DialogResult.Yes)
55 {
56 File.Delete(path2);
57 }
58 else
59 {
60 return false;
61 }
62 }
63 }
64
65 File.Move(path1, path2);
66 return true;
67 }

◆ SanitizeFilename()

static string BrawlLib.BrawlManagerLib.FileOperations.SanitizeFilename ( string  filename)
inlinestatic
315 {
316 string invalidChars =
317 System.Text.RegularExpressions.Regex.Escape(new string(Path.GetInvalidFileNameChars()));
318 string invalidRegStr = string.Format(@"([{0}]*\.+$)|([{0}]+)", invalidChars);
319
320 return System.Text.RegularExpressions.Regex.Replace(filename, invalidRegStr, "_");
321 }

The documentation for this class was generated from the following file: