示例#1
0
        [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);
        }
示例#2
0
        static public void performCommand(string[] commands)
        {
            if (commands[0].Equals(commandPrefix + "s"))
            {
                // Scan library
                Program_cli.debugMsg("Scan library selected.");
                scanLibrary();
            }
            else if (commands[0].Equals(commandPrefix + "t"))
            {
                // Tag a picture
                Program_cli.debugMsg("Tag a picture selected.");

                // First argument following the tag flag is the filename
                string filename = commands[1];
                // Remaining arguments following the tag flag are the tags to append
                //  Copy the tags from an array to a List
                string[] newTagsArray = new string[commands.Length - 2];
                Array.Copy(commands, 2, newTagsArray, 0, commands.Length - 2);
                List <String> newTags = new List <String>(newTagsArray);

                if (db.addTagsToPictureByLocation(filename, newTags))
                {
                    Program_cli.debugMsg("Tagged " + filename + " with " + newTags[0] + "...");                                                 //STUB
                }
                else
                {
                    Program_cli.errorMsg("Error tagging picture");                                                      //STUB
                }
            }
            else if (commands[0].Equals(commandPrefix + "h"))
            {
                // Set home directory
                Program_cli.debugMsg("Set home directory selected.");

                if (commands.Length == 1)
                {
                    CmdUtil.colorWriteLine("Your current home directory is " + Properties.Settings.Default.homeDirectory, ConsoleColor.Green);
                }
                else
                {
                    if (setHomeDirectory(commands[1]))
                    {
                        CmdUtil.colorWriteLine("Poof successfully changed the home directory to \"" + commands[1] + "\".", ConsoleColor.Green);
                    }
                    else
                    {
                        CmdUtil.colorWriteLine("Unfortunately, Poof can't set the home directory to a location that doesn't exist.", ConsoleColor.Green);
                    }
                }
            }
            else if (commands[0].Equals(commandPrefix + "l"))
            {
                // Output the database
                Program_cli.debugMsg("output database selected.");
                outputDatabase();                                                                                                               //STUB
            }
            else
            {
                Program_cli.errorMsg("Poof doesn't understand that command. The list of supported commands are:");
                displayHelp();
            }
        }