Exemplo n.º 1
0
 private static void ClipboardChanged(object sender, EventArgs e)
 {
     if (Clipboard.ContainsImage())
     {
         BalloonMessage.ClipboardNotification();
     }
     //if (settings.clipboardFileDrop && Clipboard.ContainsFileDropList())
     //{
     //    var files = Clipboard.GetFileDropList();
     //    var ext = Path.GetExtension(files[0]);
     //    if (ImageFileTypes.SupportedTypes.Contains(ext))
     //    {
     //        BalloonMessage.ClipboardNotification();
     //    }
     //}
 }
Exemplo n.º 2
0
 public static async Task SetGoogleDriveFileShared(string fileID, CancellationToken token)
 {
     try
     {
         JObject permission = new JObject(
             new JProperty("role", "reader"),
             new JProperty("type", "anyone"));
         HttpContent content = new StringContent(permission.ToString(Formatting.None), Encoding.UTF8, "application/json");
         var         headers = new Dictionary <string, string>
         {
             ["Authorization"] = $"Bearer {Properties.Settings.Default.gdriveToken}"
         };
         await UploadData($"https://www.googleapis.com/drive/v3/files/{fileID}/permissions", content, token, headers);
     }
     catch (Exception)
     {
         BalloonMessage.ShowMessage("Failed to set file shared", BalloonIcon.Warning);
     }
 }
Exemplo n.º 3
0
 private void ProgressAndIconChange(int pctComplete)
 {
     ProgressValue = pctComplete;
     if (pctComplete >= 10 && pctComplete < 20)
     {
         BalloonMessage.SetIcon("10");
     }
     else if (pctComplete >= 20 && pctComplete < 30)
     {
         BalloonMessage.SetIcon("20");
     }
     else if (pctComplete >= 30 && pctComplete < 40)
     {
         BalloonMessage.SetIcon("30");
     }
     else if (pctComplete >= 40 && pctComplete < 50)
     {
         BalloonMessage.SetIcon("40");
     }
     else if (pctComplete >= 50 && pctComplete < 60)
     {
         BalloonMessage.SetIcon("50");
     }
     else if (pctComplete >= 60 && pctComplete < 70)
     {
         BalloonMessage.SetIcon("60");
     }
     else if (pctComplete >= 70 && pctComplete < 80)
     {
         BalloonMessage.SetIcon("70");
     }
     else if (pctComplete >= 80 && pctComplete < 90)
     {
         BalloonMessage.SetIcon("80");
     }
     else if (pctComplete >= 90)
     {
         BalloonMessage.SetIcon("90");
     }
 }
Exemplo n.º 4
0
 public static async Task <string> GetDropboxSharedUrl(string path)
 {
     try
     {
         string s;
         using (var w = new WebClient())
         {
             w.Proxy = null;
             JObject param = new JObject(
                 new JProperty("path", path));
             w.Headers[HttpRequestHeader.Authorization] = $"Bearer {Properties.Settings.Default.dropboxToken}";
             w.Headers[HttpRequestHeader.ContentType]   = "application/json";
             s = await w.UploadStringTaskAsync("https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings", param.ToString(Formatting.None));
         }
         dynamic json = JsonConvert.DeserializeObject <ExpandoObject>(s);
         return(json.url);
     }
     catch (Exception)
     {
         BalloonMessage.ShowMessage("Failed to get shared url", BalloonIcon.Warning);
         return("");
     }
 }
Exemplo n.º 5
0
        private async void Upload()
        {
            while (!queue.IsCompleted)
            {
                CancelEnabled = false;
                if (queue.TryTake(out XImage currentUpload, Timeout.Infinite))
                {
                    try
                    {
                        var filesize = currentUpload.image?.Length ?? new FileInfo(currentUpload.filepath).Length;
                        if (filesize == 0)
                        {
                            // Empty file, get next in queue
                            continue;
                        }

                        SetStatusBarText("Uploading..");
                        cancelUpload  = new CancellationTokenSource();
                        CancelEnabled = true;
                        Tuple <string, string> result = null;
                        string  response;
                        dynamic json;
                        switch (currentUpload.Uploadsite)
                        {
                        case UploadSite.Imgur:
                        default:
                            // check if filesize exceeds service limitations
                            if (CheckFileSizeLimit(filesize, settings.fileSizeImgur))
                            {
                                currentUpload.image = null;
                                SetStatusBarText("File too large. Skipping.");
                                continue;
                            }

                            // refresh imgur token if using account
                            if (OAuthHelpers.TokenNeedsRefresh(UploadSite.Imgur) && settings.anonUpload == false)
                            {
                                SetStatusBarText("Refreshing Imgur login..");
                                BalloonMessage.SetIcon("R");
                                await OAuthHelpers.RefreshImgurToken();

                                SetStatusBarText("Uploading..");
                            }

                            // do the upload
                            response = await Uploader.HttpImgurUpload(currentUpload, settings.anonUpload, cancelUpload.Token);

                            // parse response
                            json = JsonConvert.DeserializeObject <ExpandoObject>(response);
                            // add to album if specified
                            if (!settings.anonUpload)
                            {
                                await Uploader.AddToImgurAlbum(json.data.id);
                            }

                            string thumb = $"http://i.imgur.com/{json.data.id}m.jpg";

                            result = new Tuple <string, string>(json.data.link, thumb);
                            break;

                        case UploadSite.Gyazo:
                            if (settings.gyazoToken == string.Empty)
                            {
                                // login first
                                MessageBox.Show("Login to Gyazo first!", "LXtory Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                                MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly);
                                continue;
                            }

                            if (CheckFileSizeLimit(filesize, settings.fileSizeGyazo))
                            {
                                currentUpload.image = null;
                                SetStatusBarText("File too large. Skipping.");
                                continue;
                            }
                            response = await Uploader.HttpGyazoUpload(currentUpload, cancelUpload.Token);

                            json = JsonConvert.DeserializeObject <ExpandoObject>(response);
                            string link      = json.url;
                            string thumbnail = json.thumb_url;

                            result = new Tuple <string, string>(link, thumbnail);
                            break;

                        case UploadSite.Puush:
                            if (settings.puush_key == string.Empty)
                            {
                                MessageBox.Show("Puush api key required!", "LXtory Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                                MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly);
                                continue;
                            }

                            if (CheckFileSizeLimit(filesize, settings.fileSizePuush))
                            {
                                currentUpload.image = null;
                                SetStatusBarText("File too large. Skipping.");
                                continue;
                            }
                            response = await Uploader.HttpPuushUpload(currentUpload, cancelUpload.Token);

                            string[] split = response.Split(',');
                            if (split.Length < 3)
                            {
                                throw new Exception($"Puush error\r\n{response}");
                            }
                            string t = $"http://puush.me/{split[2]}";

                            result = new Tuple <string, string>(split[1], t);
                            break;

                        case UploadSite.Dropbox:
                            if (settings.dropboxToken == string.Empty)
                            {
                                MessageBox.Show("Login to Dropbox first!", "LXtory Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                                MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly);
                                continue;
                            }
                            if (CheckFileSizeLimit(filesize, settings.fileSizeDropbox))
                            {
                                currentUpload.image = null;
                                SetStatusBarText("File too large. Skipping.");
                                continue;
                            }
                            response = await Uploader.HttpDropboxUpload(currentUpload, cancelUpload.Token);

                            json = JsonConvert.DeserializeObject <ExpandoObject>(response);
                            var path = json.path_display;
                            response = await Uploader.GetDropboxSharedUrl(path);

                            result = new Tuple <string, string>(response, "");
                            break;

                        case UploadSite.GoogleDrive:
                            if (settings.gdriveToken == string.Empty)
                            {
                                MessageBox.Show("Login to Google Drive first!", "LXtory Error", MessageBoxButton.OK, MessageBoxImage.Error,
                                                MessageBoxResult.None, MessageBoxOptions.DefaultDesktopOnly);
                                continue;
                            }

                            if (CheckFileSizeLimit(filesize, settings.fileSizeGDrive))
                            {
                                currentUpload.image = null;
                                SetStatusBarText("File too large. Skipping.");
                                continue;
                            }

                            if (OAuthHelpers.TokenNeedsRefresh(UploadSite.GoogleDrive))
                            {
                                SetStatusBarText("Refreshing GDrive login..");
                                BalloonMessage.SetIcon("R");
                                await OAuthHelpers.RefreshGoogleDriveToken();

                                SetStatusBarText("Uploading..");
                            }

                            response = await Uploader.HttpGoogleDriveUpload(currentUpload, cancelUpload.Token);

                            json = JsonConvert.DeserializeObject <ExpandoObject>(response);
                            var id = json.id;
                            await Uploader.SetGoogleDriveFileShared(id, cancelUpload.Token);

                            var url = $"https://drive.google.com/file/d/{id}/view";

                            result = new Tuple <string, string>(url, "");
                            break;

                        case UploadSite.SFTP:
                            if (settings.ftpProtocol == 0)
                            {
                                response = await Uploader.FTPUpload(currentUpload);
                            }
                            else
                            {
                                response = Uploader.SFTPUpload(currentUpload, ftpConnectionInfo, cancelUpload.Token);
                            }

                            result = new Tuple <string, string>(response, "");
                            break;
                        }
                        uiContext.Post(x => AddXimageToList(currentUpload, result.Item1, result.Item2), null);
                        BalloonMessage.SetIcon("F");
                        BalloonMessage.ShowMessage("Upload complete");

                        if (queue.Count == 0)
                        {
                            SetStatusBarText("Done");
                        }
                    }
                    catch (Exception e)
                    {
                        if (e is TaskCanceledException)
                        {
                            BalloonMessage.SetIcon("Default");
                            StatusText = "Upload task cancelled";
                            BalloonMessage.ShowMessage("Upload task cancelled", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
                            continue;
                        }
                        BalloonMessage.SetIcon("E");

                        TaskDialog dialog = new TaskDialog()
                        {
                            Caption               = "LXtory Error",
                            InstructionText       = "LXtory Error",
                            Text                  = e.Message,
                            Icon                  = TaskDialogStandardIcon.Error,
                            Cancelable            = false,
                            DetailsExpanded       = false,
                            DetailsCollapsedLabel = "Show Stack Trace",
                            DetailsExpandedLabel  = "Hide Stack Trace",
                            DetailsExpandedText   = e.StackTrace
                        };
                        dialog.Show();
                    }
                }
            }
        }