public static void FillCommandBuffer() { FileSystem.FilleCommandBufferWithFileSystem(FillBufferFileSystemOptions.IncludeFile); ProgramUtil.AddPrefixToCommandBuffer("open "); }
public static void Execute(ProgramExecutionOptions options) { if (ProgramUtil.ShowHelpIfNeeded(options)) { return; } if (CommandLineUtil.ValidateArguments(options.ParsedArguments, Validations)) { Pair <string, string> pathArg; // no need to validate this because the argument is required CommandLineUtil.TryGetArgumentByName(options.ParsedArguments, PathArgName, out pathArg); var path = pathArg.Value; bool openOnTerminal = CommandLineUtil.ArgumentExists(options.ParsedArguments, TerminalArgName); HashFile file; HashDir dir; if (FileSystem.FileExistsAndIsAvailable(path, out file)) { var permission = FileSystem.GetAccessPermission(file); if (permission < AccessPermission.Editable) { var msg = "You don't have permission to open this file."; msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } else { switch (file.FileType) { case HashFileType.Text: var textFile = file.Content as TextFile; OpenTextFile(file, textFile, openOnTerminal); break; case HashFileType.Image: var imageFile = file.Content as ImageFile; OpenImageFile(file, imageFile, openOnTerminal); break; default: DebugUtil.Error(string.Format("The open program can't open file type: {0}", file.FileType)); break; } } } else { string msg; if (FileSystem.DirExists(path, out dir)) { msg = "The path '{0}' points to a directory. Please use 'cd {0}' to navigate to that directory."; } else { msg = "The path '{0}' points to nowhere. Please supply a valida path."; } msg = string.Format(msg, path); msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } } else { string msg = "Please supply a file path."; msg = TextUtil.Error(msg); TerminalUtil.ShowText(msg); } }
private void AddDatabase(string filepath) { string filename = Path.GetFileName(filepath); string newFilePath = Path.Combine(FileSystem.DbPath, filename); // If the DB is already loaded, let user reconfigure var fileAlreadyLoaded = CheckFileLoaded(filepath); if (fileAlreadyLoaded != null) { if (MessageBox.Show("This database is already loaded. Would you like to configure it?", "Database", MessageBoxButtons.YesNo) == DialogResult.Yes) { EditDatabase(fileAlreadyLoaded); } return; } // If the DB is not loaded, but already in DB folder, we don't need to copy bool inDbFolder = CheckSameFile(filepath, newFilePath); if (!inDbFolder) { // Don't overwrite existing file if (File.Exists(newFilePath)) { if (MessageBox.Show("A database with the same filename is already exists. The new database file will be renamed.", "Database Notice", MessageBoxButtons.OKCancel) == DialogResult.OK) { newFilePath = FileSystem.GetUniqueFilename(newFilePath); } else { return; } } File.Copy(filepath, newFilePath); } // Set up some reasonable defaults var newDbEntry = new DBConfig.Database(); newDbEntry.Format = DBFormat.ClrMamePro; newDbEntry.Filename = FileSystem.MakePathRelative(FileSystem.DbPath, newFilePath); DialogResult result = DBEdit.EditEntry(newDbEntry); // If the user cancels, and the file was copied to DB folder, delete the folder. if (result == DialogResult.Cancel && !inDbFolder) { FileSystem.IgnoreFileErrors(() => File.Delete(newFilePath)); } else { Program.DatabaseConfig.Databases.Add(newDbEntry); defaultSelection = newDbEntry; } // Re-populate list PopulateList(); MakeDefaultSelection(); return; }