示例#1
0
文件: mdi.cs 项目: lanicon/Commander
        private void InstallToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Plugins|*.dll;*.exe";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var res = TryLoadPlugin(ofd.FileName);
                var ret = res.Item2;
                switch (res.Item1)
                {
                case LoadPluginResultEnum.Success:
                    Stuff.Info($"Plugin {ret.Name} loaded successfully!");
                    break;

                case LoadPluginResultEnum.Fail:
                    Stuff.Error($"Plugin {ret.Name} load error.");
                    break;

                case LoadPluginResultEnum.AlreadyExist:
                    Stuff.Warning($"Plugin {ret.Name} already loaded.");
                    break;
                }
            }
        }
示例#2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            FilesystemLibrary lib = null;

            if (listView1.Items.Count == 0)
            {
                Stuff.Error("No files to save.");
                return;
            }
            if (radioButton1.Checked)
            {
                if (!Directory.Exists(textBox3.Text))
                {
                    Stuff.Error("Directory not exist: " + textBox3.Text);
                    return;
                }
            }
            else
            {
                if (comboBox1.SelectedItem == null)
                {
                    Stuff.Error("Library to save not selected.");
                    return;
                }
                lib = (comboBox1.SelectedItem as ComboBoxItem).Tag as FilesystemLibrary;
            }
            int skipped = 0;

            foreach (var item in listView1.Items)
            {
                var uri = ((Uri)(item as ListViewItem).Tag);


                using (WebClient wc = new WebClient())
                {
                    var name = uri.Segments.Last();
                    var path = Path.Combine(textBox3.Text, name);
                    if (radioButton2.Checked)
                    {
                        path = Path.Combine((lib as FilesystemLibrary).BaseDirectory.FullName, name);
                    }
                    if (File.Exists(path))
                    {
                        skipped++;
                    }
                    wc.DownloadFile(uri.ToString(), path);
                }
            }
            toolStripStatusLabel1.Text = "Total: " + listView1.Items.Count + "; Skipped: " + skipped + "; total: " + listView1.Items.Count;
        }
示例#3
0
        private void UpdateTitleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //InitiateSSLTrust();
            // using System.Net;
            ServicePointManager.Expect100Continue = true;
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }
            if (listView1.SelectedItems[0].Tag is UrlBookmark)
            {
                var r = listView1.SelectedItems[0].Tag as UrlBookmark;

                try
                {
                    HttpWebRequest req = HttpWebRequest.Create(r.Uri.ToString()) as HttpWebRequest;

                    var resp   = req.GetResponse() as HttpWebResponse;
                    var strm   = resp.GetResponseStream();
                    var enc    = Encoding.GetEncoding(resp.CharacterSet);
                    var stream = new StreamReader(strm, enc);
                    var str    = stream.ReadToEnd();

                    //   var str = wc.DownloadString(r.Uri.ToString());

                    var list  = Stuff.ParseHtmlItems(str, "<title", "/title>");
                    var list2 = Stuff.ParseHtmlItems(str, "<meta", "/>");
                    if (list.Any())
                    {
                        var strr = list[0];
                        var s1   = strr.IndexOf('>');
                        strr = strr.Substring(s1 + 1);
                        s1   = strr.IndexOf('<');
                        strr = strr.Substring(0, s1);
                        //strr = targetEnc.GetString(Encoding.Default.GetBytes(strr));
                        Clipboard.SetText(strr);
                        r.Info = strr;
                        listView1.SelectedItems[0].SubItems[1].Text = r.Info;
                        Stuff.IsDirty = true;
                    }
                }
                catch (Exception ex)
                {
                    Stuff.Error(ex.Message);
                }
            }
        }
示例#4
0
        public void AppendUrl()
        {
            try
            {
                var txt = Clipboard.GetText();
                var arr = txt.Split(new char[] { '\r', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                listView1.BeginUpdate();
                int added      = 0;
                int duplicates = 0;
                foreach (var item in arr)
                {
                    var uri = new Uri(item);
                    if (uris.Add(uri.ToString()))
                    {
                        listView1.Items.Add(new ListViewItem(new string[] { item, uri.Segments.Last() })
                        {
                            Tag = uri
                        });
                        added++;
                    }
                    else
                    {
                        duplicates++;
                    }
                }
                toolStripStatusLabel1.Text = "Added: " + added + "; skipped: " + duplicates + "; total: " + listView1.Items.Count;
            }
            catch (Exception ex)
            {
                Stuff.Error(ex.Message);
            }
            finally
            {
                listView1.EndUpdate();
                listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
        }
示例#5
0
 private void textBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (Validation != null)
         {
             var res = Validation(textBox1.Text);
             if (res.Item1)
             {
                 DialogResult = DialogResult.OK;
                 Close();
             }
             else
             {
                 if (!string.IsNullOrEmpty(res.Item2))
                 {
                     Stuff.Error(res.Item2);
                 }
                 else
                 {
                     Stuff.Error("Invalid name.");
                 }
             }
         }
         else
         {
             DialogResult = DialogResult.OK;
             Close();
         }
     }
     if (e.KeyCode == Keys.Escape)
     {
         DialogResult = DialogResult.Cancel;
         Close();
     }
 }
示例#6
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (th == null)
            {
                button3.Text = "abort";
            }
            else
            {
                button3.Text = "download all";
                th.Abort();
                th = null;
                return;
            }
            Infos.Clear();
            savePic = true;
            //webBrowser1.ScriptErrorsSuppressed = true;
            int cnt = listView1.Items.Count;

            //calc md5 in target dir
            saveTarget = textBox1.Text;
            if (radioButton1.Checked)
            {
                var lib = (comboBox4.SelectedItem as ComboBoxItem).Tag as FilesystemLibrary;
                saveTarget = lib.BaseDirectory.FullName;
                if (checkBox6.Checked)
                {
                    saveTarget = Path.Combine(saveTarget, textBox4.Text);
                }
            }
            var dir = new DirectoryInfo(saveTarget);

            if (!dir.Exists)
            {
                Stuff.Error("directory " + dir.FullName + " not exist");
                return;
            }
            skipped = 0;
            saved   = 0;
            links   = 0;
            errors  = 0;
            List <string> ss = new List <string>();

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                ss.Add((string)listView1.Items[i].Tag);
            }
            th = new Thread(() =>
            {
                statusStrip1.Invoke((Action)(() =>
                {
                    toolStripStatusLabel1.Text = "calculating md5 hashes..";
                    toolStripProgressBar1.Value = 0;
                    toolStripProgressBar1.Visible = true;
                }));
                var fls  = dir.GetFiles().ToArray();
                int fcnt = 0;
                foreach (var item in fls)
                {
                    var md5 = Stuff.CalcMD5(new FileInfoWrapper(item.FullName));
                    md5cache.Add(md5);
                    statusStrip1.Invoke((Action)(() =>
                    {
                        toolStripStatusLabel1.Text = "md5 hash: " + fcnt + " / " + fls.Length;
                        toolStripProgressBar1.Value = (int)((fcnt / (float)fls.Length) * 100);
                    }));
                    fcnt++;
                }
                statusStrip1.Invoke((Action)(() =>
                {
                    toolStripStatusLabel1.Text = "starting downloads..";
                    toolStripProgressBar1.Value = 100;
                    toolStripProgressBar1.Visible = true;
                }));

                for (int i = 0; i < ss.Count; i++)
                {
                    statusStrip1.Invoke((Action)(() =>
                    {
                        toolStripProgressBar1.Visible = true;
                        toolStripProgressBar1.Value = (int)Math.Round(((float)i / (ss.Count)) * 100f);
                    }));
                    try
                    {
                        if (useDelay)
                        {
                            Thread.Sleep(delay);
                        }
                        var item = ss[i];
                        //  iscomplete = false;

                        //using (WebClient wc = new WebClient())
                        {
                            //  AppendHeaders(wc);
                            //  var str = wc.DownloadString(item);

                            var req = HttpWebRequest.Create(item) as HttpWebRequest;

                            AppendHeaders(req);
                            req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                            var resp = req.GetResponse() as HttpWebResponse;
                            if (resp.StatusCode != HttpStatusCode.OK)
                            {
                            }
                            var enc  = Encoding.GetEncoding(resp.CharacterSet);
                            var strm = resp.GetResponseStream();

                            StreamReader readStream = new StreamReader(strm, enc);
                            var str = readStream.ReadToEnd();


                            if (savePic)
                            {
                                savePicFunc(item, str);
                            }

                            //webBrowser1.Navigate((string)(item as ListViewItem).Tag, null, null, "User-Agent: Mozilla/5.0");
                            statusStrip1.Invoke((Action)(() =>
                            {
                                toolStripStatusLabel1.Text = "skipped: " + skipped + "  saved: " + saved + "; errors: " + errors + "; links extracted: " + links;
                            }));
                        }
                    }
                    catch (Exception ex)
                    {
                        errors++;
                    }
                }


                statusStrip1.Invoke((Action)(() =>
                {
                    toolStripStatusLabel1.Text = "skipped: " + skipped + "  saved: " + saved + "; errors: " + errors + "; links extracted: " + links;
                    toolStripProgressBar1.Value = 100;
                    toolStripProgressBar1.Visible = false;
                }));
                if (checkBox3.Checked)//close on complete
                {
                    Application.Exit();
                }
                button3.Invoke((Action)(() =>
                {
                    button3.Text = "download all";
                }));

                th = null;
            });
            th.IsBackground = true;
            th.Start();
        }