diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs index d35e5b7..713bd17 100644 --- a/ShiftOS.Objects/ShiftFS.cs +++ b/ShiftOS.Objects/ShiftFS.cs @@ -401,6 +401,63 @@ namespace ShiftOS.Objects.ShiftFS return paths.ToArray(); } + /// + /// Copies a file or directory from one path to another, deleting the original. + /// + /// THe input path, must be a valid directory or file. + /// The output path. + public static void Move(string path, string target) + { + if (FileExists(path)) + { + WriteAllBytes(target, ReadAllBytes(path)); + Delete(path); + } + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach (var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach (var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + Delete(path); + } + } + + + /// + /// Copies a file or directory from one path to another. + /// + /// The input path, must be a valid directory or file. + /// The output path. + public static void Copy(string path, string target) + { + if (FileExists(path)) + WriteAllBytes(target, ReadAllBytes(path)); + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach(var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach(var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + } + } + public static string[] GetFiles(string path) { string[] pathlist = path.Split('/'); diff --git a/ShiftOS.WinForms/Applications/FileDialog.cs b/ShiftOS.WinForms/Applications/FileDialog.cs index 308be7d..ba92f08 100644 --- a/ShiftOS.WinForms/Applications/FileDialog.cs +++ b/ShiftOS.WinForms/Applications/FileDialog.cs @@ -60,9 +60,20 @@ namespace ShiftOS.WinForms.Applications try { var itm = lvitems.SelectedItems[0]; - if (FileExists(currentdir + "/" + itm.Text)) + if (cbfiletypes.Text != "Directory") { - txtfilename.Text = itm.Text; + if (FileExists(currentdir + "/" + itm.Text)) + { + txtfilename.Text = itm.Text; + } + } + else + { + if (DirectoryExists(currentdir + "/" + itm.Text)) + { + txtfilename.Text = itm.Text; + } + } } catch { } @@ -72,23 +83,41 @@ namespace ShiftOS.WinForms.Applications { string fname = ""; fname = (!string.IsNullOrWhiteSpace(txtfilename.Text)) ? txtfilename.Text : ""; - fname = (!fname.EndsWith(cbfiletypes.SelectedItem.ToString())) ? fname + cbfiletypes.SelectedItem.ToString() : fname; - fname = (fname == cbfiletypes.SelectedItem.ToString()) ? "" : fname; + if (cbfiletypes.Text != "Directory") + { + fname = (!fname.EndsWith(cbfiletypes.SelectedItem.ToString())) ? fname + cbfiletypes.SelectedItem.ToString() : fname; + fname = (fname == cbfiletypes.SelectedItem.ToString()) ? "" : fname; + } switch (style) { case FileOpenerStyle.Open: - - if(FileExists(currentdir + "/" + fname)) + if (cbfiletypes.Text == "Directory") { - callback?.Invoke(currentdir + "/" + fname); - this.Close(); + if (DirectoryExists(currentdir + "/" + fname)) + { + callback?.Invoke(currentdir + "/" + fname); + this.Close(); + } + else + { + Infobox.Show("{FILE_NOT_FOUND}", "{FILE_NOT_FOUND_EXP}"); + } + } else { - Infobox.Show("{FILE_NOT_FOUND}", "{FILE_NOT_FOUND_EXP}"); + if (FileExists(currentdir + "/" + fname)) + { + callback?.Invoke(currentdir + "/" + fname); + this.Close(); + } + else + { + Infobox.Show("{FILE_NOT_FOUND}", "{FILE_NOT_FOUND_EXP}"); + } } break; case FileOpenerStyle.Save: diff --git a/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs b/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs index 63b61cc..91a72da 100644 --- a/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs +++ b/ShiftOS.WinForms/Applications/FileSkimmer.Designer.cs @@ -134,12 +134,14 @@ namespace ShiftOS.WinForms.Applications this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; this.copyToolStripMenuItem.Size = new System.Drawing.Size(47, 20); this.copyToolStripMenuItem.Text = "Copy"; + this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); // // moveToolStripMenuItem // this.moveToolStripMenuItem.Name = "moveToolStripMenuItem"; this.moveToolStripMenuItem.Size = new System.Drawing.Size(49, 20); this.moveToolStripMenuItem.Text = "Move"; + this.moveToolStripMenuItem.Click += new System.EventHandler(this.moveToolStripMenuItem_Click); // // FileSkimmer // diff --git a/ShiftOS.WinForms/Applications/FileSkimmer.cs b/ShiftOS.WinForms/Applications/FileSkimmer.cs index 689c718..4b11d24 100644 --- a/ShiftOS.WinForms/Applications/FileSkimmer.cs +++ b/ShiftOS.WinForms/Applications/FileSkimmer.cs @@ -324,6 +324,69 @@ namespace ShiftOS.WinForms.Applications copyToolStripMenuItem.Visible = false; } } + + private void copyToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + string path = currentdir + "/" + lvitems.SelectedItems[0].Tag.ToString(); + if (DirectoryExists(path)) + { + FileSkimmerBackend.GetFile(new[] { "Directory" }, FileOpenerStyle.Save, (newPath) => + { + Copy(path, newPath); + ResetList(); + }); + } + else if (FileExists(path)) + { + string[] psplit = path.Split('.'); + string ext = "." + psplit[psplit.Length - 1]; + FileSkimmerBackend.GetFile(new[] { ext }, FileOpenerStyle.Save, (newPath) => + { + Copy(path, newPath); + ResetList(); + }); + + } + } + catch + { + + } + } + + private void moveToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + string path = currentdir + "/" + lvitems.SelectedItems[0].Tag.ToString(); + if (DirectoryExists(path)) + { + FileSkimmerBackend.GetFile(new[] { "Directory" }, FileOpenerStyle.Save, (newPath) => + { + Utils.Move(path, newPath); + ResetList(); + }); + } + else if (FileExists(path)) + { + string[] psplit = path.Split('.'); + string ext = psplit[psplit.Length - 1]; + FileSkimmerBackend.GetFile(new[] { ext }, FileOpenerStyle.Save, (newPath) => + { + Utils.Move(path, newPath); + ResetList(); + }); + + } + } + catch + { + + } + + } }