public MainWindow() { InitializeComponent(); _mainWindow = this; if (Settings.Default.UpgradeRequired) { Settings.Default.Upgrade(); Settings.Default.UpgradeRequired = false; Settings.Default.Save(); } TrayAnimation.Init(); }
public static async void UploadImage(BitmapSource image) { var mainWindow = Application.Current.Windows .Cast <Window>() .FirstOrDefault(window => window is MainWindow) as MainWindow; // Start tray icon animation TrayAnimation.Start(); // Get bytes from image var imageFormat = Settings.Default.ImageFormat; var imageBytes = Conversion.GetBytesFromImage(image, imageFormat); // Get bytes from thumbnail var thumbBytes = Conversion.GetBytesFromThumbnail(image, imageFormat, maxPixelLength: 160); // Send images with encrypted user GUID var guidBytes = System.Text.Encoding.Unicode.GetBytes(Settings.Default.UploadKey); var csp = new RSACryptoServiceProvider(2048); var serverKey = File.ReadAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Dyysh\\ServerRsaKeyBlob"); csp.ImportCspBlob(serverKey); var encryptedGuid = csp.Encrypt(guidBytes, true); // Get url or error code var imageUrl = await Http.Upload(imageBytes, thumbBytes, encryptedGuid, imageFormat); MainWindow.ImageUrl = Dyysh.Properties.Settings.Default.ConnectionURL + imageUrl; MainWindow.ShowBalloonTip(); System.Windows.Clipboard.SetText(Settings.Default.ConnectionURL + imageUrl); // Stop tray icon animation TrayAnimation.Stop(); // Save image if proper bool is in effect if (Settings.Default.SaveToDisk) { var fileName = imageUrl.Substring(imageUrl.LastIndexOf('/') + 1); var filePath = Settings.Default.SaveLocation + "\\" + fileName; File.WriteAllBytes(filePath, imageBytes); } }