Exemple #1
0
 private void UpdateUIElements(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Result is PushBulletAPI.DevicesResponse)
     {
         var res = e.Result as PushBulletAPI.DevicesResponse;
         PushBulletAPI.SetConfigurationOption(PushBullet.conf, "apikey", apikeyInput.Text, false);
         if (doneWindowChkBox.IsChecked.HasValue)
         {
             PushBulletAPI.SetConfigurationOption(PushBullet.conf, "showDoneWindow", (bool)doneWindowChkBox.IsChecked, false);
         }
         var section = PushBulletAPI.GetResponseSection(PushBullet.conf);
         section.Devices.Clear();
         section.SharedDevices.Clear();
         foreach (PushBulletAPI.DevicesResponse.Device device in res.devices)
         {
             section.Devices.Add(device.ToDeviceConfig());
         }
         foreach (PushBulletAPI.DevicesResponse.SharedDevice sDevice in res.shared_devices)
         {
             section.SharedDevices.Add(sDevice.ToDeviceConfig());
         }
         PushBullet.conf.Save(System.Configuration.ConfigurationSaveMode.Modified);
         MessageBox.Show(Properties.Strings.SetupComplete, @"\o/", MessageBoxButton.OK, MessageBoxImage.Information);
         this.Close();
         return;
     }
     this.IsEnabled       = true;
     Mouse.OverrideCursor = null;
     apikeyInput.Clear();
 }
        private bool InitDevices()
        {
            if (devices != null)
            {
                return(true);
            }

            try
            {
                if (conf == null)
                {
                    conf = PushBulletAPI.GetSharedConfiguration("pushbullet");
                }
                var data = PushBulletAPI.GetResponseSection(this.conf);
                if (data == null)
                {
                    throw new Exception("Empty ResponseSection");
                }
                this.devices = data;
                // avoid NPEs
                //if (this.devices.Devices.Count == null) this.devices.devices = new PushBulletAPI.DevicesResponse.Device[] { };
                //if (this.devices.shared_devices == null) this.devices.shared_devices = new PushBulletAPI.DevicesResponse.SharedDevice[] { };
                if (devices.SharedDevices.Count == 0)
                {
                    MessageBox.Show("Kaboom");
                }
                return(true);
            }
            catch (Exception e)
            {
                err("Got an Exception while retrieving the devices: " + e.ToString());
                return(false);
            }
        }
 private static void UpdateDevicesCache(Configuration conf, string apikey, bool updateKey)
 {
     PushBulletAPI.Configure(apikey);
     try
     {
         var res = PushBulletAPI.GetDevices();
         if (updateKey)
         {
             PushBulletAPI.SetConfigurationOption(conf, "apikey", apikey, false);
         }
         var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PushBulletAPI.DevicesResponse));
         using (var writer = new System.IO.StringWriter())
         {
             serializer.Serialize(writer, res);
             PushBulletAPI.SetConfigurationOption(conf, "cachedDevices", writer.ToString(), true);
         }
         Console.WriteLine("OK");
     }
     catch (Exception e)
     {
         Console.Error.WriteLine("Invalid API key.");
         Console.Error.Write(e.ToString());
         System.Environment.Exit(1);
     }
 }
        private void ProcessFile()
        {
            i++;
            if (files.Length <= i || files[i] == null)
            {
                if (PushBulletAPI.GetBoolConfigurationOption(PushBullet.conf, "showDoneWindow", true))
                {
                    MessageBox.Show(Properties.Strings.UploadCompleted, "Ok", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                Application.Current.Dispatcher.BeginInvoke(new Action(() => Application.Current.Shutdown()));
                return;
            }
            Application.Current.Dispatcher.BeginInvoke(new Action(() => uploadLabel.Content = string.Format(Properties.Strings.UploadingFormatStr, Path.GetFileName(files[i]), i + 1, files.Length)));
            if (!File.Exists(files[i]))
            {
                PushBullet.ShowError(string.Format(Properties.Strings.FileDoesNotExist, files[i]));
                ProcessFile();
                return;
            }
            FileInfo info = new FileInfo(files[i]);

            if (info.Length > 0x1900000 || info.Length == 0) // 0x1900000 == 26214400 bytes == 25 MiB
            {
                PushBullet.ShowError(string.Format(Properties.Strings.IncorrectSize, files[i]));
                ProcessFile();
                return;
            }
            currentWorker                            = new BackgroundWorker();
            currentWorker.DoWork                    += RunInBackground;
            currentWorker.ProgressChanged           += UpdateProgress;
            currentWorker.RunWorkerCompleted        += UpdateUIElements;
            currentWorker.WorkerReportsProgress      = true;
            currentWorker.WorkerSupportsCancellation = true;
            Application.Current.Dispatcher.BeginInvoke(new Action(() => currentWorker.RunWorkerAsync(new string[] { deviceId, files[i] })));
        }
 public UploadGUI(string deviceId, string[] files)
 {
     InitializeComponent();
     this.deviceId = deviceId;
     this.files    = files;
     PushBulletAPI.Configure(PushBulletAPI.GetNonNullConfigurationOption(PushBullet.conf, "apikey"));
     ProcessFile();
 }
Exemple #6
0
 public APIGUI2()
 {
     InitializeComponent();
     if (PushBulletAPI.HasConfigurationOption(PushBullet.conf, "apikey"))
     {
         this.apikeyInput.Text = PushBulletAPI.GetNonNullConfigurationOption(PushBullet.conf, "apikey");
     }
     this.doneWindowChkBox.IsChecked = PushBulletAPI.GetBoolConfigurationOption(PushBullet.conf, "showDoneWindow", true);
     this.Loaded += WinLoaded;
 }
Exemple #7
0
 private void CheckAPIKeyBg(object sender, DoWorkEventArgs e)
 {
     PushBulletAPI.DevicesResponse devices;
     try
     {
         devices = PushBulletAPI.GetDevices();
     }
     catch (Exception ex)
     {
         e.Result = false;
         PushBullet.ShowError(Properties.Strings.InvalidKey + " " + ex.ToString());
         return;
     }
     e.Result = devices;
 }
        /*private PushBulletAPI.DeviceCollection GetDevices()
         * {
         *  if (conf == null)
         *      conf = PushBulletAPI.GetSharedConfiguration("pushbullet");
         *  if (!PushBulletAPI.HasConfigurationOption(conf, "apikey")) throw new Exception("No device cache available");
         *  //var serializer = new System.Xml.Serialization.XmlSerializer(typeof(PushBulletAPI.DevicesResponse));
         *  //return serializer.Deserialize(new System.IO.StringReader(PushBulletAPI.GetNonNullConfigurationOption(conf, "cachedDevices"))) as PushBulletAPI.DevicesResponse;
         *
         * }*/

        private void TryExecute(string devId)
        {
            if (conf == null)
            {
                conf = PushBulletAPI.GetSharedConfiguration("pushbullet");
            }
            if (!PushBulletAPI.HasConfigurationOption(conf, "mainPath"))
            {
                throw new Exception("No executable path available");
            }
            try
            {
                Process.Start(PushBulletAPI.GetNonNullConfigurationOption(this.conf, "mainPath"), "/upload " + devId + " " + MergePaths(this.SelectedItemPaths));
            }
            catch (Exception exa)
            {
                MessageBox.Show("An error occurred while opening the upload helper: " + exa.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void RunInBackground(object sender, DoWorkEventArgs e)
 {
     string[] arguments = (string[])e.Argument;
     try
     {
         PushBulletAPI.PushFile(arguments[0], arguments[1], OnDataUploaded);
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(System.Threading.ThreadInterruptedException))
         {
             PushBullet.ShowError(string.Format(Properties.Strings.UploadError, ex.ToString()));
         }
         else
         {
             Application.Current.Dispatcher.BeginInvoke(new Action(() => Application.Current.Shutdown()));
         }
     }
 }
Exemple #10
0
 static void Main(string[] args)
 {
     conf = PushBulletAPI.GetSharedConfiguration("pushbullet");
     PushBulletAPI.SetConfigurationOption(conf, "mainPath", System.Reflection.Assembly.GetEntryAssembly().Location, true);
     if (args != null && args.Length > 2 && args[0].Equals("/upload"))
     {
         // enter upload mode
         if (!PushBulletAPI.HasConfigurationOption(conf, "apikey") || !System.Text.RegularExpressions.Regex.IsMatch(args[1], @"^\d+$"))
         {
             ShowError(Properties.Strings.InvalidParams);
             return;
         }
         new System.Windows.Application().Run(new UploadGUI(args[1], args.Skip(2).ToArray()));
     }
     else
     {
         new System.Windows.Application().Run(new APIGUI2());
     }
 }
        static void Main(string[] args)
        {
            if (args == null || args.Length < 1)
            {
                PrintUsage();
            }
            Configuration conf = PushBulletAPI.GetSharedConfiguration("pushbullet");

            switch (args[0].Substring(1))
            {
            case "apikey":
                if (args.Length < 2 || args[1].Length != 32)
                {
                    PrintUsage();
                }
                UpdateDevicesCache(conf, args[1], true);
                break;

            case "devices":
                if (!PushBulletAPI.HasConfigurationOption(conf, "cachedDevices"))
                {
                    Console.Error.WriteLine("No device cache available.");
                    System.Environment.Exit(1);
                }
                Console.Write(PushBulletAPI.GetNonNullConfigurationOption(conf, "cachedDevices"));
                break;

            case "refresh":
                if (!PushBulletAPI.HasConfigurationOption(conf, "apikey"))
                {
                    Console.Error.WriteLine("API key not set.");
                    System.Environment.Exit(1);
                }
                UpdateDevicesCache(conf, PushBulletAPI.GetNonNullConfigurationOption(conf, "apikey"), false);
                break;

            default:
                PrintUsage();
                break;
            }
        }
Exemple #12
0
        private void OnSaveBtnClicked(object sender, RoutedEventArgs e)
        {
            var key = apikeyInput.Text;

            /* Removed this check since I'm unsure if PushBullet's APIkey
             * is always 32 characters. Since it is an MD5 hash encoded with
             * Base64, I think that Base64's padding may alter its length,
             * so better leave this commented.
             * if (key.Length != 32)
             *  PushBullet.ShowError(Properties.Strings.InvalidKey);
             * else
             * {*/
            this.IsEnabled       = false;
            Mouse.OverrideCursor = Cursors.Wait;
            PushBulletAPI.Configure(key);
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork             += CheckAPIKeyBg;
            bw.RunWorkerCompleted += UpdateUIElements;
            bw.RunWorkerAsync();
            //}
        }