Пример #1
0
        // Repopulate the data grid with the new search results
        public void FillDataGrid(List <String> tags)
        {
            dgd_Results.Rows.Clear();

            List <PasteDBRow> results;

            if (tags == null || tags.Count == 0 || tags[0] == "")
            {
                results = db.returnAll();
            }
            else
            {
                results = new List <PasteDBRow>();

                //List<PasteDBRow> dbResults = db.getTopPastesByTags(tags);
                PasteDBRow dbResults = db.getTopPasteByTags(tags);
                if (dbResults != null)
                {
                    results.Add(dbResults);
                }
            }

            if (results.Count > 0)
            {
                // Add rows to datagrid
                object[] tempobj = new object[4];
                foreach (PasteDBRow resultRow in results)
                {
                    // Set image preview
                    Image preview   = Image.FromFile(resultRow.location);
                    int   newHeight = preview.Height;
                    int   newWidth  = preview.Width;
                    if (preview.Width > preview.Height)
                    {
                        newWidth  = dgd_ROWHEIGHT;
                        newHeight = (int)(((double)dgd_ROWHEIGHT / preview.Width) * preview.Height);
                    }
                    else
                    {
                        newHeight = dgd_ROWHEIGHT;
                        newWidth  = (int)(((double)dgd_ROWHEIGHT / preview.Height) * preview.Width);
                    }
                    tempobj[0] = new Bitmap(preview, newWidth, newHeight);

                    // Add in the upload address, and tag list
                    tempobj[1] = resultRow.uploadAddress;
                    tempobj[2] = resultRow.TagsAsString;
                    tempobj[3] = resultRow.id;

                    dgd_Results.Rows.Add(tempobj);
                }

                // Size all the rows to be the proper height
                for (int rowCount = 0; rowCount < dgd_Results.Rows.Count; rowCount++)
                {
                    dgd_Results.Rows[rowCount].Height = dgd_ROWHEIGHT;
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
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);
        }