Esempio n. 1
0
        static void errorHandler(object sender, UnhandledExceptionEventArgs args)
        {
            fallyToast.Toaster general = new fallyToast.Toaster();
            general.Show("fallyGrab", "An error has occured. Check error log.", -1, "Fade", "Up", "", "", "error");

            Exception e = (Exception)args.ExceptionObject;
            commonFunctions.writeLog(e.Message,e.StackTrace);
        }
Esempio n. 2
0
 public static string UploadImage(string image)
 {
     WebClient w = new WebClient();
     w.Headers.Add("Authorization", "Client-ID " + ClientId);
     System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
     try
     {
         Keys.Add("image", Convert.ToBase64String(File.ReadAllBytes(image)));
         byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);
         dynamic result = Encoding.ASCII.GetString(responseArray);
         System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("link\":\"(.*?)\"");
         Match match = reg.Match(result);
         string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
         return url;
     }
     catch (Exception s)
     {
         fallyToast.Toaster alertform = new fallyToast.Toaster();
         alertform.Show("fallyGrab", "Imgur error: "+s.Message, -1, "Fade", "Up", "", "", "error");
         return "Failed!";
     }
 }
Esempio n. 3
0
 private void writeHistory(string url)
 {
     if (Properties.Settings.Default.history == 1)
     {
         // add to database
         SQLiteDatabase db = new SQLiteDatabase();
         Dictionary<String, String> data = new Dictionary<String, String>();
         data.Add("link", url);
         try
         {
             db.Insert("history", data);
         }
         catch (Exception crap)
         {
             fallyToast.Toaster alertdb = new fallyToast.Toaster();
             alertdb.Show("fallyGrab", crap.Message, -1, "Fade", "Up", "", "", "error");
             commonFunctions.writeLog(crap.Message, crap.StackTrace);
         }
     }
 }
Esempio n. 4
0
 private void uploadFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
         openFileDialog1.ShowDialog();
         if (File.Exists(openFileDialog1.FileName))
         {
             // copy file to save location
             File.Copy(openFileDialog1.FileName, ssfolder + "\\" + new FileInfo(openFileDialog1.FileName).Name, true);
             // process the screenshot
             string urlReturned = commonFunctions.useScreenshot(ssfolder + "\\" + new FileInfo(openFileDialog1.FileName).Name, ssfolder);
             // add link to history if returned
             if (urlReturned != "")
             {
                 writeHistory(urlReturned);
             }
         }
     }
     catch (Exception exx)
     {
         fallyToast.Toaster alertformup2 = new fallyToast.Toaster();
         alertformup2.Show("fallyGrab", "Error: " + exx.Message, -1, "Fade", "Up", "", "", "error");
         commonFunctions.writeLog(exx.Message, exx.StackTrace);
     }
 }
Esempio n. 5
0
        private void uploadFacebook(string file)
        {
            if (fallyGrab.Properties.Settings.Default.uploadType == "Facebook")
            {
                if (fallyGrab.Properties.Settings.Default.fbToken != "")
                {

                    var fb = new FacebookClient(Security.DecryptString(fallyGrab.Properties.Settings.Default.fbToken, Security.encryptionPassw));

                    fb.PostCompleted += (o, e) =>
                    {
                        if (e.Cancelled)
                        {
                            var cancellationError = e.Error;
                        }
                        else if (e.Error != null)
                        {
                            // error occurred
                            this.BeginInvoke(new MethodInvoker(
                                                 () =>
                                                 {
                                                     fallyToast.Toaster alertformfbe = new fallyToast.Toaster();
                                                     alertformfbe.Show("fallyGrab", e.Error.Message, -1, "Fade", "Up", "", "", "error");
                                                 }));
                        }
                        else
                        {
                            // the request was completed successfully

                            this.BeginInvoke(new MethodInvoker(
                                                 () =>
                                                 {
                                                     dynamic result = e.GetResultData();
                                                     string linkFB = "https://www.facebook.com/photo.php?fbid=" + result.id;
                                                     // Url shortening
                                                     string shorturl = "";
                                                     if (fallyGrab.Properties.Settings.Default.shortenUrls == 1)
                                                         shorturl = ShortUrl.shortenUrl(linkFB);

                                                     // copy to clipboard
                                                     string urlnotif = "";
                                                     if (shorturl != "")
                                                     {
                                                         System.Windows.Forms.Clipboard.SetText(shorturl);
                                                         historyMenu(shorturl);
                                                         writeHistory(shorturl);
                                                         urlnotif = shorturl;
                                                     }
                                                     else
                                                     {
                                                         System.Windows.Forms.Clipboard.SetText(linkFB);
                                                         historyMenu(linkFB);
                                                         writeHistory(linkFB);
                                                         urlnotif = linkFB;
                                                     }

                                                     fallyToast.Toaster alertformfacebook = new fallyToast.Toaster();
                                                     alertformfacebook.Show("fallyGrab", "File has been uploaded to Facebook. The link has been copied to your clipboard.", 8, "Fade", "Up",linkFB,file);
                                                 }));
                        }
                    };
                    string type = "";
                    if (Properties.Settings.Default.imageFormat == "JPG")
                        type = "image/jpeg";
                    else if (Properties.Settings.Default.imageFormat == "PNG")
                        type = "image/png";
                    dynamic parameters = new ExpandoObject();
                    parameters.message = "";
                    parameters.source = new FacebookMediaObject
                    {
                        ContentType = type,
                        FileName = Path.GetFileName(file)
                    }.SetValue(File.ReadAllBytes(file));

                    fb.PostAsync("me/photos", parameters);
                }
                else
                {
                    fallyToast.Toaster alertformfb = new fallyToast.Toaster();
                    alertformfb.Show("fallyGrab", "You must login to Facebook from the settings panel", -1, "Fade", "Up", "", "", "error");
                }
            }
        }
Esempio n. 6
0
 private void openErrorLogToolStripMenuItem_Click(object sender, EventArgs e)
 {
     string appdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
     if (File.Exists(appdatapath + "\\fallyGrab\\fallygrab_errorlog.txt"))
     {
         Process.Start(appdatapath + "\\fallyGrab\\fallygrab_errorlog.txt");
     }
     else
     {
         fallyToast.Toaster alertformhe = new fallyToast.Toaster();
         alertformhe.Show("fallyGrab", "The error log file has not been generated", 5, "Fade", "Up");
     }
 }
Esempio n. 7
0
        private void notification_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string deftray = Properties.Settings.Default.defaction;
            if (deftray == "Open history manager")
            {
                if (!isHistoryOpen())
                {
                    historyManagerForm historyform = new historyManagerForm();
                    historyform.Show();

                    // garbage collector
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }
            }
            else if (deftray == "Open file upload")
            {
                try
                {
                    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
                    openFileDialog1.ShowDialog();
                    if (File.Exists(openFileDialog1.FileName))
                    {
                        // copy file to save location
                        File.Copy(openFileDialog1.FileName, ssfolder + "\\" + new FileInfo(openFileDialog1.FileName).Name, true);
                        // process the screenshot
                        string urlReturned = commonFunctions.useScreenshot(ssfolder + "\\" + new FileInfo(openFileDialog1.FileName).Name, ssfolder);
                        // add link to history if returned
                        if (urlReturned != "")
                        {
                            writeHistory(urlReturned);
                        }
                    }
                }
                catch (Exception exx)
                {
                    // display alert
                    fallyToast.Toaster alertformup2 = new fallyToast.Toaster();
                    alertformup2.Show("fallyGrab", "Error: " + exx.Message, -1, "Fade", "Up", "", "", "error");
                    commonFunctions.writeLog(exx.Message, exx.StackTrace);
                }
            }
            else if (deftray == "Open preferences")
            {
                if (!isPreferencesOpen())
                {
                    settingsForm settingsform = new settingsForm();
                    settingsform.Show();
                }
            }
            else
            {
                string myPath = ssfolder;
                string windir = Environment.GetEnvironmentVariable("WINDIR");
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                prc.StartInfo.FileName = windir + @"\explorer.exe";
                prc.StartInfo.Arguments = myPath + @"\";
                prc.Start();
            }
        }
Esempio n. 8
0
        void hook_KeyPressed(object sender, KeyPressedEventArgs e)
        {
            // print full screen
            if (e.Key == fallyGrab.Properties.Settings.Default.keyShortcut)
            {
                // check if save folder exists
                try
                {
                    // get file name
                    string file = commonFunctions.fileName();
                    // set the bitmap object to the size of the screen
                    ImageCodecInfo myImageCodecInfo;
                    System.Drawing.Imaging.Encoder myEncoder;
                    EncoderParameter myEncoderParameter;
                    EncoderParameters myEncoderParameters;
                    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppRgb);
                    // create a graphics object from the bitmap
                    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                    // take the screenshot from the upper left corner to the right bottom corner
                    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                    // save the screenshot to the specified path that the user has chosen
                    if (fallyGrab.Properties.Settings.Default.imageFormat == "JPG")
                        myImageCodecInfo = GetEncoderInfo("image/jpeg");
                    else
                        myImageCodecInfo = GetEncoderInfo("image/png");

                     myEncoder = System.Drawing.Imaging.Encoder.Quality;
                     myEncoderParameters = new EncoderParameters(1);
                     myEncoderParameter = new EncoderParameter(myEncoder, Convert.ToInt64(fallyGrab.Properties.Settings.Default.quality));
                     myEncoderParameters.Param[0] = myEncoderParameter;
                     bmpScreenshot.Save(ssfolder + "\\fallyGrab-" + file, myImageCodecInfo, myEncoderParameters);

                    string urlReturned = "";
                    // facebook
                    if (fallyGrab.Properties.Settings.Default.uploadType == "Facebook")
                        uploadFacebook(ssfolder + "\\fallyGrab-" + file);
                    else
                        urlReturned = commonFunctions.useScreenshot(ssfolder + "\\fallyGrab-" + file,ssfolder);
                    // add link to history if returned
                    if (urlReturned != "")
                    {
                        writeHistory(urlReturned);
                    }

                }
                catch (Exception ex)
                {
                    fallyToast.Toaster alertformfolder = new fallyToast.Toaster();
                    alertformfolder.Show("fallyGrab", "Error: "+ex.Message, -1, "Fade", "Up","","","error");
                    commonFunctions.writeLog(ex.Message, ex.StackTrace);
                }
            }
            else if (e.Key == Properties.Settings.Default.keyShortcut2)
            {
                if (!isCropperOpen())
                {
                    cropperForm cropperForm = new cropperForm(this);
                    cropperForm.ssfolder = ssfolder;
                    cropperForm.ShowDialog();

                    // add to history
                    if (cropperForm.urlCrop != "")
                    {
                        string urlReturned = "";
                        // facebook
                        if (fallyGrab.Properties.Settings.Default.uploadType == "Facebook")
                            uploadFacebook(ssfolder + "\\fallyGrab-" + cropperForm.urlCrop);
                        else
                            urlReturned = commonFunctions.useScreenshot(ssfolder + "\\fallyGrab-" + cropperForm.urlCrop, ssfolder);
                        // add link to history if returned
                        if (urlReturned != "")
                        {
                            writeHistory(urlReturned);
                        }
                    }

                }
            }

            // garbage collector
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Esempio n. 9
0
        private void historyClick(object sender, EventArgs e)
        {
            var m1 = (ToolStripMenuItem)sender;
            System.Windows.Forms.Clipboard.SetText(m1.Text);
            fallyToast.Toaster alerthistoryclick = new fallyToast.Toaster();
            alerthistoryclick.Show("fallyGrab", "The link has been copied to your clipboard.", 5, "Fade", "Up");

            // garbage collector
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
Esempio n. 10
0
 private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
 {
     shortcut = (Keys)(byte)char.ToUpper(e.KeyChar);
     if (shortcut2 == shortcut) {
         fallyToast.Toaster alertformsettings2 = new fallyToast.Toaster();
         alertformsettings2.Show("fallyGrab", "You cannot use the same key for both shortcuts", -1, "Fade", "Up", "", "", "error");
     }
     else
     {
         if (e.KeyChar.ToString().Trim() == "" || (int)e.KeyChar <= 127)
             textBox4.Text = shortcut.ToString();
         else
             textBox4.Text = e.KeyChar.ToString();
     }
 }
Esempio n. 11
0
 /// <summary>
 ///     Allows the programmer to easily insert into the DB
 /// </summary>
 /// <param name="tableName">The table into which we insert the data.</param>
 /// <param name="data">A dictionary containing the column names and data for the insert.</param>
 /// <returns>A boolean true or false to signify success or failure.</returns>
 public bool Insert(String tableName, Dictionary<String, String> data)
 {
     String columns = "";
     String values = "";
     Boolean returnCode = true;
     foreach (KeyValuePair<String, String> val in data)
     {
         columns += String.Format(" {0},", val.Key.ToString());
         values += String.Format(" '{0}',", val.Value);
     }
     columns = columns.Substring(0, columns.Length - 1);
     values = values.Substring(0, values.Length - 1);
     try
     {
         this.ExecuteNonQuery(String.Format("insert into {0}({1}) values({2});", tableName, columns, values));
     }
     catch (Exception fail)
     {
         fallyToast.Toaster alertdb = new fallyToast.Toaster();
         alertdb.Show("fallyGrab", fail.Message, -1, "Fade", "Up", "", "", "error");
         returnCode = false;
     }
     return returnCode;
 }
Esempio n. 12
0
 /// <summary>
 ///     Allows the programmer to easily delete rows from the DB.
 /// </summary>
 /// <param name="tableName">The table from which to delete.</param>
 /// <param name="where">The where clause for the delete.</param>
 /// <returns>A boolean true or false to signify success or failure.</returns>
 public bool Delete(String tableName, String where)
 {
     Boolean returnCode = true;
     try
     {
         this.ExecuteNonQuery(String.Format("delete from {0} where {1};", tableName, where));
     }
     catch (Exception fail)
     {
         fallyToast.Toaster alertdb = new fallyToast.Toaster();
         alertdb.Show("fallyGrab", fail.Message, -1, "Fade", "Up", "", "", "error");
         returnCode = false;
     }
     return returnCode;
 }
Esempio n. 13
0
        public static string useScreenshot(string file, string ssfolder)
        {
            string retLink = "";
            // uploading
            // FTP
            if (fallyGrab.Properties.Settings.Default.uploadType == "FTP")
            {
                // validation
                if (fallyGrab.Properties.Settings.Default.ftpServer != "" && fallyGrab.Properties.Settings.Default.ftpUsername != "" && fallyGrab.Properties.Settings.Default.ftpPassword != "" && fallyGrab.Properties.Settings.Default.ftpPublic != "")
                {
                    upload upform = new upload();
                    upform.file = new FileInfo(file).Name;
                    upform.ssfolder = ssfolder;
                    upform.fullname = file;
                    upform.Show();
                    // return link for menu
                    if (upform.linkreturned != "")
                        retLink = upform.linkreturned;
                    upform.Close();
                }
                else
                {
                    fallyToast.Toaster alertform = new fallyToast.Toaster();
                    alertform.Show("fallyGrab", "You must enter your ftp server details in the application preferences", -1, "Fade", "Up", "", "", "error");
                }
            }
            // Dropbox
            else if (fallyGrab.Properties.Settings.Default.uploadType == "Dropbox")
            {
                if (fallyGrab.Properties.Settings.Default.dropboxRoot != "" && fallyGrab.Properties.Settings.Default.dropboxUser != "")
                {
                    string dbRoot = fallyGrab.Properties.Settings.Default.dropboxRoot;
                    string saveLocation = ssfolder;
                    if (saveLocation.Substring(saveLocation.Length - 1, 1) == @"\")
                        saveLocation = saveLocation.Substring(0, saveLocation.Length - 2);
                    if (dbRoot.Substring(dbRoot.Length - 1, 1) == @"\")
                        dbRoot = dbRoot.Substring(0, dbRoot.Length - 2);

                    string folder = saveLocation.Replace(dbRoot, "");

                    folder = folder.Replace(@"\Public", "");

                    if (folder != "" && folder.Substring(0, 1) == @"\")
                        folder = folder.Substring(1, folder.Length - 1);
                    if (folder != "" && folder.Substring(folder.Length - 1, 1) != @"\")
                        folder = folder + "/";

                    // Url shortening
                    string shorturl = "";
                    string normalurl = "http://dl.dropbox.com/u/" + fallyGrab.Properties.Settings.Default.dropboxUser + "/" + folder + new FileInfo(file).Name;
                    if (fallyGrab.Properties.Settings.Default.shortenUrls == 1)
                        shorturl = ShortUrl.shortenUrl("http://dl.dropbox.com/u/" + fallyGrab.Properties.Settings.Default.dropboxUser + "/" + folder + new FileInfo(file).Name);

                    // copy to clipboard
                    if (shorturl != "")
                    {
                        System.Windows.Forms.Clipboard.SetText(shorturl);
                        retLink = shorturl;
                    }
                    else
                    {
                        System.Windows.Forms.Clipboard.SetText("http://dl.dropbox.com/u/" + fallyGrab.Properties.Settings.Default.dropboxUser + "/" + folder + new FileInfo(file).Name);
                        retLink = "http://dl.dropbox.com/u/" + fallyGrab.Properties.Settings.Default.dropboxUser + "/" + folder + new FileInfo(file).Name;
                    }

                    // show notification
                    fallyToast.Toaster alertformdropbox = new fallyToast.Toaster();
                    alertformdropbox.Show("fallyGrab", "File has been uploaded to Dropbox. The link has been copied to your clipboard.", 8, "Fade", "Up", normalurl, file);
                }
                else
                {
                    fallyToast.Toaster alertformdberror = new fallyToast.Toaster();
                    alertformdberror.Show("fallyGrab", "You must enter your Dropbox details", -1, "Fade", "Up", "", "", "error");
                }
            }
            // Imgur
            else if (fallyGrab.Properties.Settings.Default.uploadType == "Imgur")
            {
                // do the upload
                string url = Imgur.UploadImage(file);

                // Url shortening
                string shorturl = "";
                if (fallyGrab.Properties.Settings.Default.shortenUrls == 1)
                    shorturl = ShortUrl.shortenUrl(url);

                // copy to clipboard
                if (shorturl != "")
                {
                    System.Windows.Forms.Clipboard.SetText(shorturl);
                    retLink = shorturl;
                }
                else
                {
                    System.Windows.Forms.Clipboard.SetText(url);
                    retLink = url;
                }

                // show notification
                fallyToast.Toaster alertformimgur = new fallyToast.Toaster();
                alertformimgur.Show("fallyGrab", "File has been uploaded to Imgur. The link has been copied to your clipboard.", 8, "Fade", "Up", url, file);
            }
            // none
            else
            {
                fallyToast.Toaster alertformnone = new fallyToast.Toaster();
                alertformnone.Show("fallyGrab", "Your screenshot has been saved", 8, "Fade", "Up", "", file);
                retLink = file;
            }
            return retLink;
        }
Esempio n. 14
0
        private void cropper_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {

                // check if save folder exists
                try
                {
                    // get file name
                    string file = commonFunctions.fileName();
                    // set the bitmap object to the size of the screen
                    ImageCodecInfo myImageCodecInfo;
                    System.Drawing.Imaging.Encoder myEncoder;
                    EncoderParameter myEncoderParameter;
                    EncoderParameters myEncoderParameters;
                    bmpScreenshot = new Bitmap(this.Size.Width - 2 * VIRTUALBORDER, this.Size.Height - 2 * VIRTUALBORDER, PixelFormat.Format32bppRgb);
                    // create a graphics object from the bitmap
                    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                    // remove background
                    this.Opacity = 0;
                    // take the screenshot from the upper left corner to the right bottom corner
                    gfxScreenshot.CopyFromScreen(this.Location.X + VIRTUALBORDER, this.Location.Y + VIRTUALBORDER, 0, 0, new Size(this.Size.Width - 2 * VIRTUALBORDER, this.Size.Height - 2 * VIRTUALBORDER), CopyPixelOperation.SourceCopy);
                    // close stillshot
                    ssForm.Close();
                    this.Hide();
                    // save the screenshot to the specified path that the user has chosen
                    if (fallyGrab.Properties.Settings.Default.imageFormat == "JPG")
                        myImageCodecInfo = GetEncoderInfo("image/jpeg");
                    else
                        myImageCodecInfo = GetEncoderInfo("image/png");
                    myEncoder = System.Drawing.Imaging.Encoder.Quality;
                    myEncoderParameters = new EncoderParameters(1);
                    myEncoderParameter = new EncoderParameter(myEncoder, Convert.ToInt64(fallyGrab.Properties.Settings.Default.quality));
                    myEncoderParameters.Param[0] = myEncoderParameter;
                    bmpScreenshot.Save(ssfolder + "\\fallyGrab-" + file, myImageCodecInfo, myEncoderParameters);
                    // add link to history if returned
                    urlCrop = file;
                    // close form
                    this.Dispose();
                    this.Close();
                }
                catch (Exception ex)
                {
                    fallyToast.Toaster alertformfolder = new fallyToast.Toaster();
                    alertformfolder.Show("fallyGrab", "Error: " + ex.Message, -1, "Fade", "Up", "", "", "error");
                    commonFunctions.writeLog(ex.Message, ex.StackTrace);
                    // garbage collector
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                }
            }
            else if (e.KeyChar == (char)Keys.Escape)
            {
                // close stillshot
                ssForm.Close();
                // close form
                this.Close();
                this.Dispose();
            }
        }