Пример #1
0
 private void BtnProcess_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         StringBuilder result = new StringBuilder();
         result.Append("static byte file[] =\r\n{\r\n");
         using (var file = File.Open(FFSInput.SelectedPath, FileMode.Open))
         {
             int    count;
             byte[] buffer = new byte[4096];
             do
             {
                 count = file.Read(buffer, 0, buffer.Length);
                 result.Append(ArrayToText(buffer, count, (int)EsBytesRow.Value));
             }while (count > 0);
             result.Remove(result.Length - 2, 2);
             result.AppendLine("};");
             Output.Text = result.ToString();
         }
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #2
0
        public void SwitchImage(int index = -1)
        {
            try
            {
                if (Items == null)
                {
                    return;
                }
                if (index > -1)
                {
                    Index = index;
                }
                switch (Display.SelectedIndex)
                {
                case 0:
                    Image2.Source         = new BitmapImage(new Uri(Items[Index].Path));
                    Container2.Background = GetDominantColor(Items[Index].Path);
                    Display.SelectedIndex++;
                    break;

                case 1:
                    Image1.Source         = new BitmapImage(new Uri(Items[Index].Path));
                    Container1.Background = GetDominantColor(Items[Index].Path);
                    Display.SelectedIndex--;
                    break;
                }
            }
            catch (Exception ex)
            {
                WpfHelpers.ExceptionDialog(ex);
            }
        }
Пример #3
0
        private void Load(string dir)
        {
            _dir         = dir;
            DocumentName = Path.GetFileName(dir);
            _files.Clear();
            List <string> files = new List <string>();

            files.AddRange(Directory.GetFiles(_dir, "*.ino", SearchOption.TopDirectoryOnly));
            files.AddRange(Directory.GetFiles(_dir, "*.pde", SearchOption.TopDirectoryOnly));
            foreach (var file in files)
            {
                try
                {
                    var    text    = File.OpenText(file);
                    string content = text.ReadToEnd();
                    text.Close();
                    string key = System.IO.Path.GetFileName(file);
                    _files.Add(key, content);
                }
                catch (IOException ex)
                {
                    WpfHelpers.ExceptionDialog("Error Loading sketch: " + _dir, ex);
                    _files.Clear();
                    FilePanel.ItemsSource = null;
                    return;
                }
            }
            FilePanel.ItemsSource = null;
            FilePanel.ItemsSource = _files;
        }
Пример #4
0
        private void BtnRename_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (FilePanel.SelectedIndex < 0)
            {
                return;
            }
            TextInputWindow ti = new TextInputWindow();

            ti.Title = "Enter new file name:";
            if (ti.ShowDialog() == true)
            {
                string oldkey = GetKey(FilePanel.SelectedIndex);
                if (File.Exists(_dir + "\\" + oldkey))
                {
                    try
                    {
                        File.Move(_dir + "\\" + oldkey, _dir + "\\" + ti.InputText);
                    }
                    catch (IOException ex)
                    {
                        WpfHelpers.ExceptionDialog("Error renaming file: " + oldkey, ex);
                        return;
                    }
                }
                _files.Add(ti.InputText, _files[oldkey]);
                _files.Remove(oldkey);
            }
        }
 private void InputByNumbers()
 {
     _variables = (int)MintermNumbers.Value;
     try
     {
         if (string.IsNullOrEmpty(MintermInput.Text))
         {
             throw new Exception("No minterm numbers entered");
         }
         string[] items    = MintermInput.Text.Split(',');
         string[] dontcare = null;
         if (!string.IsNullOrEmpty(DontcarInput.Text))
         {
             dontcare = DontcarInput.Text.Split(',');
             if (dontcare.Length < 1)
             {
                 items = DontcarInput.Text.Split(' ');
             }
         }
         if (items.Length < 1)
         {
             items = MintermInput.Text.Split(' ');
         }
         if (items.Length < 1)
         {
             throw new Exception("Incorrect input");
         }
         List <LogicItem> litems = new List <LogicItem>();
         foreach (var item in items)
         {
             litems.Add(new LogicItem()
             {
                 Index       = Convert.ToInt32(item),
                 BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables),
                 Checked     = true
             });
         }
         if (dontcare != null)
         {
             foreach (var item in dontcare)
             {
                 litems.Add(new LogicItem()
                 {
                     Index       = Convert.ToInt32(item),
                     BinaryValue = LogicItem.GetBinaryValue(Convert.ToInt32(item), _variables),
                     Checked     = null
                 });
             }
         }
         SimpleMinterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, false);
         SimpleMaxterm.Text = QuineMcclusky.GetSimplified(litems, _variables, (bool)HazardSafe.IsChecked, (bool)LsbBit.IsChecked, true);
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #6
0
        private void SaveDirectory(string directorypath)
        {
            _dir = directorypath;
            string newkey = GetKey(FilePanel.SelectedIndex);

            _files[newkey] = Editor.Text;

            if (Directory.GetFiles(_dir).Length > 0)
            {
                WpfHelpers.ExceptionDialog("Target directory is not empty, can't save sketch");
                return;
            }

            var sketchname = Path.GetFileName(_dir) + ".ino";

            if (!_files.ContainsKey(sketchname))
            {
                MainSelectorWindow ms = new MainSelectorWindow();
                ms.ListItems = (from i in _files.Keys select i).ToArray();
                if (ms.ShowDialog() == true)
                {
                    string selected = ms.SelectedFile;
                    if (string.IsNullOrEmpty(selected))
                    {
                        WpfHelpers.ExceptionDialog("Save can't be completeted, because no main file is selected");
                        return;
                    }
                    string content = _files[selected];
                    _files.Remove(selected);
                    _files.Add(sketchname + ".ino", content);
                }
                else
                {
                    WpfHelpers.ExceptionDialog("Save can't be completeted, because no main file is selected");
                    return;
                }
            }

            foreach (var file in _files)
            {
                try
                {
                    var text = File.CreateText(directorypath + "\\" + file.Key + ".new");
                    text.Write(file.Value);
                    text.Close();
                    File.Move(directorypath + "\\" + file.Key + ".new", directorypath + "\\" + file.Key);
                }
                catch (IOException ex)
                {
                    WpfHelpers.ExceptionDialog("Error saving sketch: " + directorypath, ex);
                    break;
                }
            }

            Load(_dir);
        }
Пример #7
0
 private string Save()
 {
     try
     {
         XmlSerializer ser        = new XmlSerializer(typeof(UserCode));
         StringWriter  textWriter = new StringWriter();
         ser.Serialize(textWriter, _codes.ToArray());
         return(ser.ToString());
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
         return(null);
     }
 }
Пример #8
0
 public static void Save(LauncherConfig cf, string path)
 {
     try
     {
         XmlSerializer xs = new XmlSerializer(typeof(LauncherConfig));
         using (var file = File.Create(path))
         {
             xs.Serialize(file, cf);
         }
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #9
0
 public static LauncherConfig Load(string path)
 {
     try
     {
         XmlSerializer xs = new XmlSerializer(typeof(LauncherConfig));
         using (var file = File.OpenRead(path))
         {
             return((LauncherConfig)xs.Deserialize(file));
         }
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
         return(null);
     }
 }
Пример #10
0
 private void BtnLoadBMP_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
         ofd.Filter = "Bitmap files | *.bmp";
         if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             LoadBmp(ofd.FileName);
         }
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #11
0
        private void PopOut_Click(object sender, RoutedEventArgs e)
        {
            UIElement          control = null;
            UIElement          clone   = null;
            ShaderTabPopoutWin popout;
            bool disposeable;

            if (Tabs.Items.Count < 1)
            {
                return;
            }
            control     = GetCurrentControl();
            disposeable = control is IDisposable;

            if (control is IFixedTool)
            {
                WpfHelpers.ExceptionDialog("The Current tool doesn't support this function");
                return;
            }

            if (disposeable)
            {
                MessageBoxResult r = MessageBox.Show("Warning. Poping out this tool to a new window will reset it's workflow.\r\nDo you want to continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                if (r == MessageBoxResult.No)
                {
                    return;
                }
                clone = (UIElement)Activator.CreateInstance(control.GetType());
                DestroyObject(control as IDisposable);
            }

            popout            = new ShaderTabPopoutWin();
            popout.Width      = this.ActualWidth;
            popout.Height     = this.ActualHeight;
            popout.GlassTitle = (Tabs.Items[Tabs.SelectedIndex] as TabItem).Header.ToString();

            RemoveCurrenctontrol();
            if (disposeable)
            {
                popout.TabContent = clone;
            }
            else
            {
                popout.TabContent = control;
            }
            popout.Show();
        }
        private void ListDirectory(TreeView treeView, string path)
        {
            if (!File.Exists(path + "\\arduino.exe"))
            {
                WpfHelpers.ExceptionDialog("This is not a valid arduino directory. No Arduino.exe was found");
                return;
            }

            treeView.Items.Clear();
            var rootDirectoryInfo = new DirectoryInfo(path);

            treeView.Items.Add(CreateDirectoryNode(rootDirectoryInfo));
            if (treeView.Items.Count > 0)
            {
                (treeView.Items[0] as TreeViewItem).IsExpanded = true;
            }
        }
Пример #13
0
 private void BtnSaveBmp_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog();
         sfd.DefaultExt = "*.bmp";
         sfd.Filter     = "Bitmap files | *.bmp";
         if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             SaveBmp(sfd.FileName);
         }
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #14
0
        void Book_Click(object sender, RoutedEventArgs e)
        {
            var d = sender.ToString();

            if (!BookManager.PDFReaderInstalled())
            {
                WpfHelpers.ExceptionDialog("No PDF Readers installed. To view documents a PDF reader must be installed");
                return;
            }
            string  f = _books.GetFilePath(d);
            Process p = new Process();

            p.StartInfo.UseShellExecute = true;
            p.StartInfo.FileName        = f;
            p.Start();
            App._Config.UsageStats[d] += 1;
        }
Пример #15
0
        private void UpdateVariableScope()
        {
            try
            {
                if (!(bool)BtnEnable.IsChecked)
                {
                    return;
                }

                StringBuilder sb    = new StringBuilder();
                int           count = Convert.ToInt32((ToggleNumber.SelectedItem as ComboBoxItem).Content);
                ToggleButton  btn;
                for (int i = 0; i < count; i++)
                {
                    btn = TogleButtons.Children[i] as ToggleButton;
                    sb.Append(letters[i]);
                    sb.Append(" = ");
                    if (btn.IsChecked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                    sb.Append("\r\n");
                }
                ScriptSource source = _engine.CreateScriptSourceFromString(sb.ToString(), SourceCodeKind.AutoDetect);
                source.Execute(_scope);

                foreach (var f in _collection)
                {
                    source = _engine.CreateScriptSourceFromString(f.Formula, SourceCodeKind.AutoDetect);
                    object result = source.Execute(_scope);
                    f.Res = result.ToString();
                }
                Formulas.ItemsSource = null;
                Formulas.ItemsSource = _collection;
            }
            catch (Exception ex)
            {
                WpfHelpers.ExceptionDialog(ex);
            }
        }
Пример #16
0
 public void Save()
 {
     try
     {
         XmlSerializer ser        = new XmlSerializer(typeof(Config));
         StringWriter  textWriter = new StringWriter();
         Config        conf       = new Config();
         conf.Stats   = this._stats.Pack();
         conf.Configs = this._subconfigs;
         ser.Serialize(textWriter, conf);
         Settings.Default.UserConfigXML = textWriter.ToString();
         Settings.Default.Save();
         conf = null;
         textWriter.Close();
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #17
0
 private void Load(string serializeddata)
 {
     try
     {
         if (string.IsNullOrEmpty(serializeddata))
         {
             return;
         }
         XmlSerializer ser          = new XmlSerializer(typeof(UserCode));
         StringReader  stringReader = new StringReader(serializeddata);
         UserCode[]    loaded       = (UserCode[])ser.Deserialize(stringReader);
         _codes.Clear();
         _codes.AddRange(loaded);
         loaded = null;
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #18
0
 public void Load(string fileName)
 {
     if (!File.Exists(fileName))
     {
         MessageBox.Show("File not found: " + fileName, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     try
     {
         DynamicFileByteProvider dynamicFileByteProvider;
         try
         {
             // try to open in write mode
             dynamicFileByteProvider = new DynamicFileByteProvider(fileName);
         }
         catch (IOException) // write mode failed
         {
             try
             {
                 // try to open in read-only mode
                 dynamicFileByteProvider = new DynamicFileByteProvider(fileName, true);
                 if (MessageBox.Show("File is readonly. Open in reafonly mode?", "Question", MessageBoxButton.YesNo) == MessageBoxResult.No)
                 {
                     dynamicFileByteProvider.Dispose();
                     return;
                 }
             }
             catch (IOException) // read-only also failed
             {
                 // file cannot be opened
                 MessageBox.Show("File open failed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
         }
         hexBox.ByteProvider = dynamicFileByteProvider;
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #19
0
 private void ToolClicked(object sender, RoutedEventArgs e)
 {
     try
     {
         var d    = sender.ToString();
         var tool = (from i in App._Tools where i.Description == d select i).FirstOrDefault();
         if (tool != null)
         {
             MainWin.RunTool(tool);
         }
         else
         {
             var external = (from i in App._ExtTools where i.Description == d select i).FirstOrDefault();
             if (external != null)
             {
                 MainWin.RunETool(external);
             }
             else
             {
                 var web = (from i in App._WebTools where i.Description == d select i).FirstOrDefault();
                 if (web != null)
                 {
                     MainWin.RunWebTool(web);
                 }
                 else
                 {
                     var pop = (from i in App._Popups where i.Description == d select i).FirstOrDefault();
                     if (pop != null)
                     {
                         MainWin.RunPopupTool(pop);
                     }
                 }
             }
         }
         App._Config.UsageStats[d] += 1;
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #20
0
 private async void Button_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (!this.StartIP.HasValidAdress || !this.EndIP.HasValidAdress)
         {
             return;
         }
         _scanner.IPStart   = this.StartIP.IP;
         _scanner.IPEnd     = this.EndIP.IP;
         PbProgress.Maximum = _scanner.GetCount();
         cts = new CancellationTokenSource();
         Tabs.SelectedIndex     = 0;
         BtnStartStop.IsEnabled = false;
         await scann(Indicator, cts.Token, (bool)ChkScanPorts.IsChecked);
     }
     catch (Exception)
     {
         WpfHelpers.ExceptionDialog("Scan Canceled");
     }
 }
Пример #21
0
 private void BtnDeleteAll_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var q = MessageBox.Show("Delete listed files? The operation can't be undone when complete.", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (q == MessageBoxResult.No)
         {
             return;
         }
         foreach (var file in _files)
         {
             File.Delete(file);
         }
         _files.Clear();
         LbResults.ItemsSource = null;
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #22
0
 public void Load()
 {
     if (string.IsNullOrEmpty(Settings.Default.UserConfigXML))
     {
         return;
     }
     try
     {
         XmlSerializer ser          = new XmlSerializer(typeof(Config));
         StringReader  stringReader = new StringReader(Settings.Default.UserConfigXML);
         Config        loaded       = (Config)ser.Deserialize(stringReader);
         this._stats.Unpack(loaded.Stats);
         this._subconfigs = loaded.Configs;
         loaded           = null;
         stringReader.Close();
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #23
0
        private void BtnDelete_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (FilePanel.SelectedIndex < 0)
            {
                return;
            }
            string key = GetKey(FilePanel.SelectedIndex);

            if (File.Exists(_dir + "\\" + key))
            {
                try
                {
                    File.Delete(_dir + "\\" + key);
                }
                catch (IOException ex)
                {
                    WpfHelpers.ExceptionDialog("Error removing file: " + key, ex);
                    return;
                }
                _files.Remove(key);
            }
        }
Пример #24
0
 private void BtnDelete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         var q = MessageBox.Show("Delete selected files? The operation can't be undone when complete.", "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (q == MessageBoxResult.No)
         {
             return;
         }
         for (int i = 0; i < LbResults.SelectedItems.Count; i++)
         {
             string item = LbResults.SelectedItems[i].ToString();
             _files.Remove(item);
             File.Delete(item);
         }
         LbResults.ItemsSource = null;
         LbResults.ItemsSource = _files;
     }
     catch (Exception ex)
     {
         WpfHelpers.ExceptionDialog(ex);
     }
 }
Пример #25
0
        public void Save(string file)
        {
            if (hexBox.ByteProvider == null)
            {
                return;
            }
            try
            {
                DynamicFileByteProvider dynamicFileByteProvider = hexBox.ByteProvider as DynamicFileByteProvider;
                Stream target = File.Create(file);

                using (BinaryWriter bw = new BinaryWriter(target))
                {
                    for (int i = 0; i < dynamicFileByteProvider.Length; i++)
                    {
                        bw.Write(dynamicFileByteProvider.ReadByte(i));
                    }
                }
            }
            catch (Exception ex)
            {
                WpfHelpers.ExceptionDialog(ex);
            }
        }
Пример #26
0
        private async void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            BtnStart.IsEnabled   = false;
            Modeselect.IsEnabled = false;
            HashAlgorithms alg = HashAlgorithms.MD5;

            cts = new CancellationTokenSource();
            try
            {
                switch (Modeselect.SelectedIndex)
                {
                case 0:
                    TbOutput.Clear();
                    string specials = null;
                    string gen      = null;
                    if ((bool)CbSpecial.IsChecked)
                    {
                        specials = TbSpecials.Text;
                    }
                    for (int i = 0; i < SlNumber.Value; i++)
                    {
                        gen = Cryptog.GeneratePassWord((bool)CbLowercase.IsChecked, (bool)CbLowercase.IsChecked, (bool)CbNumbers.IsChecked, specials, (int)SlLength.Value);
                        TbOutput.AppendText(gen + "\r\n");
                    }
                    break;

                case 1:
                    TbCaesarOutput.Clear();

                    if (RbCaesarEnc.IsChecked == true)
                    {
                        var rules = CaesarRules.Classic;
                        if (RbCaesarRandom.IsChecked == true)
                        {
                            rules = CaesarRules.Random;
                        }
                        TbCaesarKeyRule.Text = CaesarRules.SerializeRule(rules);
                        TbCaesarOutput.Text  = Cryptog.CaesarCrypt(TbCaesarInput.Text, rules, false);
                    }
                    else
                    {
                        var rules = CaesarRules.DeserializeRule(TbCaesarKeyRule.Text);
                        TbCaesarOutput.Text = Cryptog.CaesarCrypt(TbCaesarInput.Text, rules, true);
                    }

                    break;

                case 2:
                    if ((bool)RbMD5f.IsChecked)
                    {
                        alg = HashAlgorithms.MD5;
                    }
                    else if ((bool)RbSHA1f.IsChecked)
                    {
                        alg = HashAlgorithms.SHA1;
                    }
                    else if ((bool)RbSHA256f.IsChecked)
                    {
                        alg = HashAlgorithms.SHA256;
                    }
                    else if ((bool)RbSHA512f.IsChecked)
                    {
                        alg = HashAlgorithms.SHA512;
                    }

                    string hash = await Cryptog.ComputeHashTask(cts.Token, FInput.SelectedPath, Indicator, alg);

                    TbHashOutput.Text = hash;
                    break;

                case 3:
                    if ((bool)RbMD5s.IsChecked)
                    {
                        alg = HashAlgorithms.MD5;
                    }
                    else if ((bool)RbSHA1s.IsChecked)
                    {
                        alg = HashAlgorithms.SHA1;
                    }
                    else if ((bool)RbSHA256s.IsChecked)
                    {
                        alg = HashAlgorithms.SHA256;
                    }
                    else if ((bool)RbSHA512s.IsChecked)
                    {
                        alg = HashAlgorithms.SHA512;
                    }

                    string ret = Cryptog.HashInputString(TbHashStringInput.Text, alg);
                    TbHashStringOutput.Text = ret;
                    break;

                case 4:
                    await Cryptog.XorEncryptTask(cts.Token, XorIn.SelectedPath, XorKey.SelectedPath, XorOut.SelectedPath, Indicator);

                    break;

                case 5:
                    KeySizeAES keysize = KeySizeAES.bit128;
                    if ((bool)RbAesK128.IsChecked)
                    {
                        keysize = KeySizeAES.bit128;
                    }
                    else if ((bool)RbAesK192.IsChecked)
                    {
                        keysize = KeySizeAES.bit192;
                    }
                    else if ((bool)RbAesK256.IsChecked)
                    {
                        keysize = KeySizeAES.bit256;
                    }

                    if ((bool)RbAesEnc.IsChecked)
                    {
                        TbAesKey.Text = await Cryptog.AesEncryptTask(cts.Token, AesIn.SelectedPath, AesOut.SelectedPath, keysize, Indicator);
                    }
                    else if ((bool)RbAesDec.IsChecked)
                    {
                        await Cryptog.AesDecryptTask(cts.Token, AesIn.SelectedPath, AesOut.SelectedPath, TbAesKey.Text, Indicator);
                    }
                    break;
                }
            }
            catch (OperationCanceledException)
            {
                WpfHelpers.ExceptionDialog("Task Canceled");
            }
            Modeselect.IsEnabled = true;
            BtnStart.IsEnabled   = true;
        }