// Initailize the form public frm_Search() { InitializeComponent(); try { // Initialize the database db = new PasteDB(Path.Combine(Properties.Settings.Default.homeDirectory, "poof.accdb")); if (!db.Connect()) { db.makeDB(); db.Connect(); } } catch (Exception ex) { MessageBox.Show( "Unable to connect to the database. Even tried making a new one, but still no dice.\n\n Make sure '" + Properties.Settings.Default.homeDirectory + "' exists and is writable, then try again.", "Error connecting to the database", MessageBoxButtons.OK, MessageBoxIcon.Error ); this.Close(); } FillDataGrid(null); }
static void Main(string[] args) { // On first startup, set the homeDirectory (default to @"%userprofile%\Poof\") if (Properties.Settings.Default.homeDirectory == "") { Program_cli.debugMsg("No home directory found. First start?"); string homeDir = System.Environment.GetEnvironmentVariable("userprofile") + @"\Poof\"; CmdUtil.colorWriteLine("Poof wants to set your paste directory to \"" + homeDir + "\"" + Environment.NewLine + ". If this is okay, press enter. Else, enter a new directory.", ConsoleColor.Green); string input = System.Console.ReadLine(); if (input.Length > 0) { homeDir = input; } setHomeDirectory(homeDir); Properties.Settings.Default.Save(); } // On debug, set up my test directory useTestDirectory(); try { // Initialize the database db = new PasteDB(Path.Combine(Properties.Settings.Default.homeDirectory, "poof.accdb")); if (!db.Connect()) { db.makeDB(); db.Connect(); } if (args.Length == 0) { // No arguments given. User doesn't know what they're doing; Display help text displayHelp(); } else if ( args[0].Length >= (commandPrefix.Length + 1) && args[0].Substring(0, commandPrefix.Length).Equals(commandPrefix) ) { // First argument is a command. Perform the command using all the remaining arguments performCommand(args); } else { // search the arguments as a list of tags for the best match List<String> tags = new List<string>(); foreach (String arg in args) { tags.Add(arg); } PasteDBRow pasteResult = db.getTopPasteByTags(tags); if (pasteResult != null) { displayPaste(pasteResult.uploadAddress); } else { // no results CmdUtil.colorWriteLine("Alas, no results were found.", ConsoleColor.DarkRed); } } db.Close(); } catch(Exception ex) { Program_cli.errorMsg(ex.ToString()); CmdUtil.displayFatalError(); } CmdUtil.colorWriteLine("\n«poof!»", ConsoleColor.DarkMagenta); }
[STAThread] // Single-threaded for use of the clipboard static void Main(string[] args) { // On first startup, set the homeDirectory (default to @"%userprofile%\Poof\") if (Properties.Settings.Default.homeDirectory == "") { Program_cli.debugMsg("No home directory found. First start?"); string homeDir = System.Environment.GetEnvironmentVariable("userprofile") + @"\Poof\"; CmdUtil.colorWriteLine("Poof wants to set your paste directory to \"" + homeDir + "\"" + Environment.NewLine + ". If this is okay, press enter. Else, enter a new directory.", ConsoleColor.Green); string input = System.Console.ReadLine(); if (input.Length > 0) { homeDir = input; } setHomeDirectory(homeDir); Properties.Settings.Default.Save(); } // On debug, set up my test directory useTestDirectory(); try { // Initialize the database db = new PasteDB(Path.Combine(Properties.Settings.Default.homeDirectory, "poof.accdb")); if (!db.Connect()) { db.makeDB(); db.Connect(); } if (args.Length == 0) { // No arguments given. User doesn't know what they're doing; Display help text displayHelp(); } else if ( args[0].Length >= (commandPrefix.Length + 1) && args[0].Substring(0, commandPrefix.Length).Equals(commandPrefix) ) { // First argument is a command. Perform the command using all the remaining arguments performCommand(args); } else { // search the arguments as a list of tags for the best match List <String> tags = new List <string>(); foreach (String arg in args) { tags.Add(arg); } PasteDBRow pasteResult = db.getTopPasteByTags(tags); if (pasteResult != null) { displayPaste(pasteResult.uploadAddress); } else { // no results CmdUtil.colorWriteLine("Alas, no results were found.", ConsoleColor.DarkRed); } } db.Close(); } catch (Exception ex) { Program_cli.errorMsg(ex.ToString()); CmdUtil.displayFatalError(); } CmdUtil.colorWriteLine("\n«poof!»", ConsoleColor.DarkMagenta); }