Ejemplo n.º 1
0
        private void btndeletefile_Click(object sender, EventArgs e)
        {
            string path = lvfiles.SelectedItems[0].Tag.ToString();

            if (path.StartsWith("/Shiftum42") || path.StartsWith("/SoftwareData"))
            {
                CurrentSystem.ShowInfo("Permission denied.", $"You do not have permission to delete {path}.");
                return;
            }

            var fs = CurrentSystem.GetFilesystem();

            if (fs.DirectoryExists(path))
            {
                CurrentSystem.AskYesNo("Delete folder?", $"Do you erally want to delete {path}?", (answer) =>
                {
                    if (answer)
                    {
                        fs.DeleteDirectory(path, true);
                        UpdateFolderList();
                    }
                });
            }
            else if (fs.FileExists(path))
            {
                CurrentSystem.AskYesNo("Delete file?", $"Do you erally want to delete {path}?", (answer) =>
                {
                    if (answer)
                    {
                        fs.DeleteFile(path);
                        UpdateFolderList();
                    }
                });
            }
        }
Ejemplo n.º 2
0
        private void HandleFileOpen()
        {
            var fs = CurrentSystem.GetFilesystem();

            switch (Mode)
            {
            case FileSkimmerMode.Open:
                if (lvfiles.SelectedItems.Count == 0)
                {
                    CurrentSystem.ShowInfo("Open File", "No file has been selected.");
                    return;
                }
                string path = lvfiles.SelectedItems[0].Tag.ToString();
                if (fs.FileExists(path))
                {
                    if (FileOpenCallback?.Invoke(path) == true)
                    {
                        Close();
                        return;
                    }
                }
                else
                {
                    CurrentSystem.ShowInfo("Open File", "File not found.");
                    return;
                }
                break;

            case FileSkimmerMode.Save:
                string work = _working;
                string name = txtfilename.Text;

                if (string.IsNullOrWhiteSpace(name))
                {
                    CurrentSystem.ShowInfo("Save File", "Please enter a file name.");
                    return;
                }

                if (!name.ToLower().EndsWith(lbextention.Text))
                {
                    name += lbextention.Text;
                }

                if (name.Any(x => Path.GetInvalidFileNameChars().Contains(x)))
                {
                    CurrentSystem.ShowInfo("Save File", "The file name you entered contains some invalid characters.");
                    return;
                }

                string savePath = "";
                if (work.EndsWith("/"))
                {
                    savePath = work + name;
                }
                else
                {
                    savePath = work + "/" + name;
                }

                if (savePath.StartsWith("/Shiftum42") || savePath.StartsWith("/SoftwareData"))
                {
                    CurrentSystem.ShowInfo("Permission denied.", "You do not have permission to save here.");
                    return;
                }

                if (fs.FileExists(savePath))
                {
                    CurrentSystem.AskYesNo("Save File - Overwrite?", "A file with that name already exists. Do you want to overwrite it?", (answer) =>
                    {
                        if (FileOpenCallback?.Invoke(savePath) == true)
                        {
                            Close();
                            return;
                        }
                    });
                    return;
                }
                else
                {
                    if (FileOpenCallback?.Invoke(savePath) == true)
                    {
                        Close();
                        return;
                    }
                }
                break;
            }
        }