Ejemplo n.º 1
0
        void UpdateIcons()
        {
            if (listView1.TopItem == null)
            {
                return;
            }
            for (int i = listView1.TopItem.Index; i < listView1.Items.Count; i++)
            {
                if (!listView1.IsItemVisible(listView1.Items[i]))
                {
                    break;
                }
                if (listView1.Items[i].ImageIndex != -1)
                {
                    continue;
                }

                Tuple <Bitmap, int> tp = null;
                var fileInfo           = listView1.Items[i].Tag as IFileInfo;
                if (fileInfo == null)
                {
                    continue;
                }

                if (File.Exists(fileInfo.FullName))
                {
                    tp = Stuff.GetBitmapOfFile(fileInfo.FullName);
                }

                int iindex = -1;
                if (tp != null)
                {
                    iindex = tp.Item2;
                }
                listView1.Items[i].ImageIndex = iindex;
            }
        }
Ejemplo n.º 2
0
        private void DeleteAllButThisToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //delete all and merge tags
            if (listView2.SelectedItems.Count == 0)
            {
                return;
            }
            var fli = listView2.SelectedItems[0].Tag as IFileInfo;

            if (Stuff.Question("Are you sure to delete all files in this group except " + fli.FullName + ", and merge all tags into it?") != DialogResult.Yes)
            {
                return;
            }

            List <TagInfo> tags = new List <TagInfo>();

            for (int i = 0; i < listView2.Items.Count; i++)
            {
                var fl = listView2.Items[i].Tag as IFileInfo;
                if (fl == fli)
                {
                    continue;
                }
                var tgs = Stuff.GetAllTagsOfFile(fl.FullName);
                tags.AddRange(tgs);
                fl.Filesystem.DeleteFile(fl);
            }
            tags = tags.Distinct().ToList();
            foreach (var item in tags)
            {
                if (item.ContainsFile(fli))
                {
                    continue;
                }
                item.AddFile(fli);
            }
        }
Ejemplo n.º 3
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "*.zip|*.zip";
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (var zip = ZipFile.OpenRead(ofd.FileName))
            {
                var bkm = zip.Entries.FirstOrDefault(z => z.Name.Contains("bookmarks.xml"));
                if (bkm != null)
                {
                    using (var f = bkm.Open())
                    {
                        var doc = XDocument.Load(f);
                        Stuff.LoadBookmarks(doc.Descendants("root").First());
                    }
                }
            }
            Stuff.Info("Import complete!");
        }
Ejemplo n.º 4
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();
     }
 }
Ejemplo n.º 5
0
        private void KeywordsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var minf = Stuff.GetMetaInfoOfFile(FileInfo);

            if (minf == null)
            {
                Stuff.MetaInfos.Add(new FileMetaInfo()
                {
                    File = FileInfo
                });
                minf = Stuff.MetaInfos.Last();
            }

            if (minf.Infos.Any(z => z is KeywordsMetaInfo))
            {
                return;
            }
            minf.Infos.Add(new KeywordsMetaInfo()
            {
                Parent = minf
            });
            Stuff.IsDirty = true;
            UpdateList();
        }
Ejemplo n.º 6
0
        public void UpdateList(TagInfo tag)
        {
            if (tag == null)
            {
                listView1.Items.Clear();
                //listView1.View = View.List;
                parent.CurrentTag = null;

                var filter = parent.Filter;
                var fltrs  = filter.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(z => z.ToLower()).ToArray();


                List <TagInfoCover> covers = new List <TagInfoCover>();
                foreach (var item in Stuff.Tags)
                {
                    covers.Add(new TagInfoCover()
                    {
                        Name = item.Name, TagInfo = item, IsMain = true
                    });
                    foreach (var sitem in item.Synonyms)
                    {
                        covers.Add(new TagInfoCover()
                        {
                            Name = sitem, TagInfo = item
                        });
                    }
                }
                foreach (var item in covers.OrderBy(z => z.Name))
                {
                    if (!Stuff.ShowHidden && item.TagInfo.IsHidden)
                    {
                        continue;
                    }
                    if (!IsFilterPass(item.Name, fltrs))
                    {
                        continue;
                    }
                    if (item.IsMain)
                    {
                        listView1.Items.Add(new ListViewItem(new string[] { item.Name, item.TagInfo.Files.Count() + "" })
                        {
                            Tag = item.TagInfo
                        });
                    }
                    else
                    {
                        listView1.Items.Add(new ListViewItem(new string[] { item.Name + $" ({item.TagInfo.Name})", item.TagInfo.Files.Count() + "" })
                        {
                            Tag = item
                        });
                    }
                }
            }
            else
            {
                listView1.Items.Clear();
                //listView1.View = View.Details;
                //   fc.SetPath(path);
                //textBox1.Text = path;
                parent.CurrentTag = tag;
                CurrentTag        = tag;
                parent.SetPath(tag.Name);
                var filter = parent.Filter;

                // var p = new DirectoryInfo(path);
                //   fc.CurrentDirectory = p;


                var fltrs = filter.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(z => z.ToLower()).ToArray();

                listView1.SmallImageList = Stuff.list;
                listView1.LargeImageList = Stuff.list;

                listView1.Items.Add(new ListViewItem(new string[] { "..", "", "" })
                {
                    Tag = tagRootObject
                });
                foreach (var finfo in tag.Files)
                {
                    try
                    {
                        if (!Stuff.ShowHidden)
                        {
                            var tags = Stuff.GetAllTagsOfFile(finfo.FullName);
                            if (tags.Any(z => z.IsHidden))
                            {
                                continue;
                            }
                        }
                        var f = finfo;
                        //var tp = FileListControl.GetBitmapOfFile(f.FullName);
                        //bmp.MakeTransparent();
                        // list.Images.Add(bmp);
                        if (!IsFilterPass(f.Name, fltrs))
                        {
                            continue;
                        }
                        //  int iindex = -1;

                        /* if (tp != null)
                         * {
                         *   iindex = tp.Item2;
                         * }*/
                        listView1.Items.Add(
                            new ListViewItem(new string[]
                        {
                            f.Name, Stuff.GetUserFriendlyFileSize(f.Length)
                        })
                        {
                            Tag = f,
                            //   ImageIndex = iindex
                        });
                    }
                    catch (FileNotFoundException ex)
                    {
                        listView1.Items.Add(
                            new ListViewItem(new string[]
                        {
                            Path.GetFileName(finfo.FullName)
                        })
                        {
                            BackColor = Color.LightPink,
                            Tag       = new Tuple <IFileInfo, Exception>(finfo, ex),
                        });
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private void toolStripButton1_Click_1(object sender, EventArgs e)
 {
     Stuff.SaveMeta(FileInfo);
 }
Ejemplo n.º 8
0
 public MountListWindow()
 {
     InitializeComponent();
     Stuff.SetDoubleBuffered(listView1);
     UpdateList();
 }
Ejemplo n.º 9
0
 public SearchFilterControl()
 {
     InitializeComponent();
     Stuff.SetDoubleBuffered(listView1);
     comboBox1.SelectedIndex = 0;
 }
Ejemplo n.º 10
0
 private void Timer1_Tick(object sender, EventArgs e)
 {
     textBox1.Text = "threads: " + Process.GetCurrentProcess().Threads.Count + "; RAM: " + Stuff.GetUserFriendlyFileSize(Process.GetCurrentProcess().PrivateMemorySize);
 }
Ejemplo n.º 11
0
        internal void Init(IDirectoryInfo d)
        {
            if (th != null)
            {
                return;
            }
            GC.Collect();
            toolStripProgressBar1.Visible = true;
            toolStripProgressBar1.Value   = 0;
            timer2.Enabled = false;
            ready          = false;
            Items.Clear();
            Root = null;
            //files.Clear();
            th = new Thread(() =>
            {
                var dirs = Stuff.GetAllDirs(d);

                Queue <ScannerItemInfo> q = new Queue <ScannerItemInfo>();
                int cnt = 0;
                Root    = new ScannerDirInfo(null, d);
                q.Enqueue(Root);
                Items.Add(Root);
                while (q.Any())
                {
                    ReportProgress(cnt, dirs.Count);
                    var _dd = q.Dequeue();
                    if (_dd is ScannerFileInfo)
                    {
                        continue;
                    }

                    var dd = _dd as ScannerDirInfo;

                    /* var sz = Stuff.GetDirectorySize(dd.Dir);
                     * if (sz < 1024 * 1024)
                     * {
                     *   dd.HiddenItemsSize = sz;
                     *   continue;
                     * }*/
                    cnt++;
                    try
                    {
                        foreach (var item in dd.Dir.GetFiles())
                        {
                            if (item.Length > 10 * 1024 * 1024)
                            {
                                // dd.HiddenItemsSize += item.Length;
                                //continue;
                            }
                            dd.Items.Add(new ScannerFileInfo(dd, item));
                            Items.Add(dd.Items.Last());
                            //     files.Add(item);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        foreach (var item in dd.Dir.GetDirectories())
                        {
                            var t = new ScannerDirInfo(dd, item);
                            Items.Add(t);
                            dd.Items.Add(t);
                            q.Enqueue(t);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    if (dd.Parent != null)
                    {
                        dd.Dir = null;
                    }
                }
                ReportProgress(cnt, cnt);
                Root.CalcSize();
                ready = true;
                statusStrip1.Invoke((Action)(() =>
                {
                    timer2.Enabled = true;
                    timer2.Interval = 2000;
                }));

                th = null;
            });
            th.IsBackground = true;
            th.Start();
        }
Ejemplo n.º 12
0
 private void HideToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Stuff.SetShowHidden(false);
     fileListControl1.UpdateAllLists();
     fileListControl2.UpdateAllLists();
 }
Ejemplo n.º 13
0
        public static void IndexFile(IFileInfo selectedFile)
        {
            StringBuilder sbb = new StringBuilder();

            if (selectedFile.Extension.ToLower().EndsWith("pdf"))
            {
                using (var pdoc = PdfDocument.Load(selectedFile.FullName))
                {
                    for (int i = 0; i < pdoc.PageCount; i++)
                    {
                        var txt = pdoc.GetPdfText(i);
                        sbb.Append(txt);
                    }
                    if (sbb.Length == 0)
                    {
                        if (Stuff.Question("Pdf document is not recognized. Perform OCR?") == DialogResult.Yes)
                        {
                            var img = pdoc.Render(0, 96, 96, PdfRenderFlags.None);
                            Clipboard.SetImage(img);
                            Warning("Not implemented yet.");
                        }
                    }
                    else
                    {
                        Stuff.AddIndex(new IndexInfo()
                        {
                            Path = selectedFile.FullName, Text = sbb.ToString()
                        });
                        Stuff.Info("Indexing compete: " + sbb.ToString().Length + " symbols.");
                    }
                }
                return;
            }
            if (!selectedFile.Extension.ToLower().EndsWith("djvu"))
            {
                return;
            }

            DjvuDocument doc = new DjvuDocument(selectedFile.FullName);
            var          cnt = doc.Pages.Count();

            for (int i = 0; i < cnt; i++)
            {
                var txt = doc.Pages[i].GetTextForLocation(new System.Drawing.Rectangle(0, 0, doc.Pages[i].Width, doc.Pages[i].Height));
                sbb.AppendLine(txt.Replace("\r", "").Replace("\t", ""));
            }

            Stuff.AddIndex(new IndexInfo()
            {
                Path = selectedFile.FullName, Text = sbb.ToString()
            });
            Stuff.Info("Indexing compete: " + sbb.ToString().Length + " symbols.");

            /*page
             *  .BuildPageImage()
             *  .Save("TestImage1.png", ImageFormat.Png);
             *
             * page.IsInverted = true;
             *
             * page
             *  .BuildPageImage()
             *  .Save("TestImage2.png", ImageFormat.Png);*/
        }
Ejemplo n.º 14
0
        private void isoExtractAction(FileListControl arg1, IFileInfo arg2)
        {
            var target = arg1;

            if (target == fileListControl1)
            {
                target = fileListControl2;
            }
            else
            {
                target = fileListControl1;
            }
            using (var fs = new FileStream(arg2.FullName, FileMode.Open, FileAccess.Read))
            {
                IsoReader reader = new IsoReader();
                reader.Parse(fs);
                var pvd = reader.WorkPvd;

                string savePath = Path.Combine(target.CurrentDirectory.FullName, Path.GetFileNameWithoutExtension(arg2.Name));
                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }
                var ret = DirectoryRecord.GetAllRecords(pvd.RootDir);

                foreach (var directoryRecord in ret)
                {
                    if (!directoryRecord.IsDirectory)
                    {
                        continue;
                    }
                    if (directoryRecord.LBA == pvd.RootDir.LBA)
                    {
                        continue;
                    }
                    if (directoryRecord.Parent != null && directoryRecord.Parent.LBA == directoryRecord.LBA)
                    {
                        continue;
                    }
                    if (directoryRecord.Parent != null &&
                        directoryRecord.Parent.Parent != null &&
                        directoryRecord.Parent.Parent.LBA == directoryRecord.LBA)
                    {
                        continue;
                    }

                    var pp = Path.Combine(savePath, directoryRecord.FullPath);
                    if (!Directory.Exists(pp))
                    {
                        Directory.CreateDirectory(pp);
                    }
                }


                foreach (var directoryRecord in ret)
                {
                    if (!directoryRecord.IsFile)
                    {
                        continue;
                    }
                    var data = directoryRecord.GetFileData(fs, pvd);
                    var pp   = Path.Combine(savePath, directoryRecord.FullPath);
                    File.WriteAllBytes(pp, data);
                }

                Stuff.Info("Extraction complete!");
            }
        }
Ejemplo n.º 15
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                /*FileListControl fc = null;
                 * if (fileListControl1.ContainsFocus)
                 * {
                 *  fc = fileListControl1;
                 * }
                 * if (fileListControl2.ContainsFocus)
                 * {
                 *  fc = fileListControl2;
                 * }
                 *
                 * if (fc != null && fc.ListView.Focused && fc.SelectedFile != null)
                 * {
                 *  ProcessStartInfo psi = new ProcessStartInfo();
                 *  psi.WorkingDirectory = fc.SelectedFile.DirectoryName;
                 *  psi.FileName = fc.SelectedFile.FullName;
                 *
                 *  Process.Start(psi);
                 *
                 * }*/
            }

            //if (e.KeyCode == Keys.Delete)
            //{
            //    FileListControl fc = null;
            //    if (fileListControl1.ContainsFocus)
            //    {
            //        fc = fileListControl1;
            //    }
            //    if (fileListControl2.ContainsFocus)
            //    {
            //        fc = fileListControl2;
            //    }

            //    if (fc != null && fc.ListView.Focused)
            //    {
            //        if (Stuff.Question("Delete file: " + fc.SelectedFile.FullName + "?") == DialogResult.Yes)
            //        {
            //            var attr = File.GetAttributes(fc.SelectedFile.FullName);
            //            bool allow = true;
            //            if (attr.HasFlag(FileAttributes.ReadOnly))
            //            {
            //                if (Stuff.Question("File is read-only, do you want to delete it anyway?") != DialogResult.Yes)
            //                {
            //                    allow = false;
            //                }
            //                else
            //                {
            //                    File.SetAttributes(fc.SelectedFile.FullName, FileAttributes.Normal);
            //                }
            //            }
            //            if (allow)
            //            {
            //                File.Delete(fc.SelectedFile.FullName);
            //            }
            //        }
            //    }
            //}

            if (e.KeyCode == Keys.F2)
            {//rename
                FileListControl fc = null;
                if (fileListControl1.ContainsFocus)
                {
                    fc = fileListControl1;
                }
                if (fileListControl2.ContainsFocus)
                {
                    fc = fileListControl2;
                }
                if (fc != null)
                {
                    fc.Rename();
                }
            }

            if (Stuff.Hotkeys.Any(z => z.Hotkey == e.KeyCode && z.IsEnabled))
            {
                var cc = Stuff.Hotkeys.First(z => z.Hotkey == e.KeyCode);

                IFileListControl fl = fileListControl1;
                if (fileListControl2.ContainsFocus)
                {
                    fl = fileListControl2;
                }
                cc.Execute(fl);
            }


            if (e.KeyCode == Keys.F5)
            {//copy
                if (fileListControl1.Mode == ViewModeEnum.Filesystem && fileListControl2.Mode == ViewModeEnum.Filesystem)
                {
                    var from = fileListControl1;
                    var to   = fileListControl2;
                    if (fileListControl2.ContainsFocus)
                    {
                        from = fileListControl2;
                        to   = fileListControl1;
                    }

                    /*if (from.SelectedFiles != null)
                     * {
                     *  bool allow = true;
                     *  var p1 = Path.Combine(to.CurrentDirectory.FullName,
                     *      from.SelectedFile.Name);
                     *  if (File.Exists(p1))
                     *  {
                     *      if (MessageBox.Show(
                     *              "File " + p1 + " already exist. replace?", Text,
                     *              MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                     *      {
                     *          allow = false;
                     *      }
                     *  }
                     *
                     *  if (allow)
                     *  {
                     *      File.Copy(from.SelectedFile.FullName, p1, true);
                     *      to.UpdateList(to.CurrentDirectory.FullName);
                     *  }
                     * }*/
                    var self = from.SelectedFiles;
                    var seld = from.SelectedDirectories;
                    if (seld != null || self != null)
                    {
                        //copy recursively all files and dirs
                        var prnt = from.CurrentDirectory;
                        List <IFileInfo>      list = new List <IFileInfo>();
                        List <IDirectoryInfo> dirs = new List <IDirectoryInfo>();
                        if (self != null)
                        {
                            list.AddRange(self);
                        }
                        if (seld != null)
                        {
                            foreach (var item in seld)
                            {
                                Stuff.GetAllFiles(item, list);
                                Stuff.GetAllDirs(item, dirs);
                            }
                        }


                        CopyDialog cpd = new CopyDialog();
                        cpd.Init(list.ToArray(), dirs.ToArray(), to.CurrentDirectory, prnt);
                        cpd.ShowDialog();
                    }
                }

                if ((fileListControl1.Mode == ViewModeEnum.Filesystem || fileListControl1.Mode == ViewModeEnum.Libraries) &&
                    fileListControl2.Mode == ViewModeEnum.Tags)
                {
                    if (fileListControl1.SelectedFile != null && fileListControl2.CurrentTag != null)
                    {
                        var fn = fileListControl1.SelectedFile;
                        if (!fileListControl2.CurrentTag.ContainsFile(fn))
                        {
                            fileListControl2.CurrentTag.AddFile(fn);
                            MessageBox.Show(Path.GetFileName(fn.FullName) + " tagged as " + fileListControl2.CurrentTag.Name);
                            fileListControl2.UpdateTagsList();
                        }
                    }
                }
            }
            base.OnKeyDown(e);
        }
Ejemplo n.º 16
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (searchThread != null)
            {
                button1.Text = "Start";
                searchThread.Abort();
                searchThread = null;
                return;
            }
            button1.Text = "Stop";

            var spl = textBox1.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            var dd  = (spl.Select(z => new DirectoryInfoWrapper(z))).OfType <IDirectoryInfo>().ToList();

            if (tagStorageSearchMode)
            {
                dd = Stuff.Tags.Select(z => new VirtualDirectoryInfo(null)
                {
                    ChildsFiles = z.Files.Select(u => u).OfType <IFileInfo>().ToList()
                }).OfType <IDirectoryInfo>().ToList();
            }

            if (checkBox2.Checked)
            {
                dd.Clear();
                var vfs = new VirtualFilesystem()
                {
                    UseIndexes = true
                };

                var vdir = new VirtualDirectoryInfo(vfs);
                vdir.Name     = "indexes";
                vdir.FullName = "indexes";


                foreach (var item in Stuff.Indexes)
                {
                    vdir.ChildsFiles.Add(new VirtualFileInfo(new FileInfoWrapper(item.Path), vdir));
                }
                vfs.Files.AddRange(vdir.ChildsFiles.OfType <VirtualFileInfo>());
                dd.Add(vdir);
            }

            searchThread = new Thread(() =>
            {
                List <IFileInfo> files = new List <IFileInfo>();

                if (tagStorageSearchMode)
                {
                    foreach (var item in Stuff.Tags)
                    {
                        files.AddRange(item.Files.Select(z => z));
                    }
                }
                else
                {
                    foreach (var item in dd)
                    {
                        files.AddRange(Stuff.GetAllFiles(item, level: 0, maxlevel: (int)numericUpDown1.Value));
                    }
                }

                progressBar1.Invoke((Action)(() =>
                {
                    progressBar1.Value = 0;
                    progressBar1.Maximum = files.Count;
                }));


                listView2.Items.Clear();
                searchHash.Clear();

                if (checkBox3.Checked)
                {
                    var b = pictureBox1.Image as Bitmap;
                    b.SetResolution(96, 96);
                    imgHashInt = ImagesDeduplicationWindow.GetImageHash2D(b);
                    //imgHash = ImagesDeduplicationWindow.ToHash(imgHashInt);
                }
                foreach (var d in dd)
                {
                    loop(d, () =>
                    {
                        progressBar1.Invoke((Action)(() =>
                        {
                            progressBar1.Value++;
                        }));
                    }, (int)numericUpDown1.Value);
                }

                //rec1(d, () => { progressBar1.Value++; });
                progressBar1.Invoke((Action)(() =>
                {
                    toolStripStatusLabel1.Text = "Files found: " + listView2.Items.Count;
                    button1.Text = "Start";
                }));
                searchThread = null;
            });
            searchThread.IsBackground = true;
            searchThread.Start();
        }
Ejemplo n.º 17
0
        public void loop(IDirectoryInfo _d, Action fileProcessed, int?maxLevel)
        {
            Queue <QueueItem> q = new Queue <QueueItem>();

            q.Enqueue(new commander.TextSearchForm.QueueItem(_d, 0));
            while (q.Any())
            {
                var dd = q.Dequeue();
                if (maxLevel != null)
                {
                    if (dd.Level > maxLevel)
                    {
                        continue;
                    }
                }
                var d = dd.Info;
                label4.Invoke((Action)(() =>
                {
                    label4.Text = d.FullName;
                }));

                try
                {
                    foreach (var item in d.GetFiles())
                    {
                        try
                        {
                            fileProcessed();
                            if (!IsExtFilterPass(textBox3.Text, item.Extension))
                            {
                                continue;
                            }
                            if (!IsMd5FilterPass(textBox6.Text, item))
                            {
                                continue;
                            }
                            if (!IsImageFilter(item))
                            {
                                continue;
                            }
                            if (tagStorageSearchMode)
                            {
                                if (!tagFilters.All(z => z.ContainsFile(item.FullName)))
                                {
                                    continue;
                                }
                                if (!exceptTagFilters.All(z => !z.ContainsFile(item.FullName)))
                                {
                                    continue;
                                }
                                if (!searchHash.Add(item.FullName))
                                {
                                    continue;
                                }
                            }
                            //if (!item.Extension.Contains(textBox3.Text)) continue;
                            if (!item.Name.ToLower().Contains(textBox4.Text.ToLower()))
                            {
                                continue;
                            }


                            if (!item.Name.ToLower().Contains(textBox4.Text.ToLower()))
                            {
                                continue;
                            }

                            bool add = false;
                            if (!string.IsNullOrEmpty(textBox2.Text))
                            {
                                var t = d.Filesystem.ReadAllLines(item.FullName);
                                if (t.Any(z => z.ToUpper().Contains(textBox2.Text.ToUpper())))
                                {
                                    add = true;
                                }
                            }
                            else
                            {
                                add = true;
                            }


                            #region meta check
                            if (!string.IsNullOrEmpty(textBox9.Text))
                            {
                                var mt = Stuff.GetMetaInfoOfFile(item);
                                if (mt == null)
                                {
                                    continue;
                                }
                                if (mt.Infos.Any(z => z is KeywordsMetaInfo))
                                {
                                    var k = mt.Infos.First(z => z is KeywordsMetaInfo) as KeywordsMetaInfo;
                                    if (!k.Keywords.ToLower().Contains(textBox9.Text.ToLower()))
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            #endregion

                            if (add)
                            {
                                listView2.BeginUpdate();
                                listView2.Items.Add(new ListViewItem(new string[] { item.Name })
                                {
                                    Tag = item
                                });
                                listView2.EndUpdate();
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    foreach (var item in d.GetDirectories())
                    {
                        q.Enqueue(new QueueItem(item, dd.Level + 1));
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                }
            }
        }
Ejemplo n.º 18
0
        private void ImgDedupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            var tag = listView1.SelectedItems[0].Tag;

            if (tag is TagInfo)
            {
                var dd    = listView1.SelectedItems[0].Tag as TagInfo;
                var files = dd.Files.Select(z => z);

                DedupContext ctx = new DedupContext(new IDirectoryInfo[] { }, files.OfType <IFileInfo>().ToArray());

                ProgressBarOperationDialog pd = new ProgressBarOperationDialog();
                IFileInfo[][] groups          = null;
                pd.Init(() =>
                {
                    groups = ImagesDeduplicationWindow.FindDuplicates(ctx, (p, max, title) => pd.SetProgress(title, p, max));
                    pd.Complete();
                });
                pd.ShowDialog();
                if (pd.DialogResult == DialogResult.Abort)
                {
                    return;
                }


                if (groups.Count() == 0)
                {
                    Stuff.Info("No duplicates found.");
                }
                else
                {
                    ImagesDeduplicationWindow rp = new ImagesDeduplicationWindow();
                    rp.MdiParent = mdi.MainForm;
                    rp.SetGroups(ctx, groups.ToArray());
                    rp.Show();
                }
            }
            else
            {
                List <IFileInfo>      ff = new List <IFileInfo>();
                List <IDirectoryInfo> dd = new List <IDirectoryInfo>();
                for (int i = 0; i < listView1.SelectedItems.Count; i++)
                {
                    var tag0 = listView1.SelectedItems[i].Tag;
                    if (tag0 is IFileInfo)
                    {
                        ff.Add(tag0 as IFileInfo);
                    }
                    if (tag0 is IDirectoryInfo)
                    {
                        dd.Add(tag0 as IDirectoryInfo);
                    }
                }
                DedupContext ctx = new DedupContext(dd.ToArray(), ff.ToArray());
                ProgressBarOperationDialog pd = new ProgressBarOperationDialog();
                IFileInfo[][] groups          = null;
                pd.Init(() =>
                {
                    groups = ImagesDeduplicationWindow.FindDuplicates(ctx, (p, max, title) => pd.SetProgress(title, p, max));
                    pd.Complete();
                });
                pd.ShowDialog();
                if (pd.DialogResult == DialogResult.Abort)
                {
                    return;
                }
                if (groups.Count() == 0)
                {
                    Stuff.Info("No duplicates found.");
                }
                else
                {
                    ImagesDeduplicationWindow rp = new ImagesDeduplicationWindow();
                    rp.MdiParent = mdi.MainForm;
                    rp.SetGroups(ctx, groups.ToArray());
                    rp.Show();
                }
            }
        }
Ejemplo n.º 19
0
        public void savePicFunc(string _uri, string str)
        {
            //extract ajax?
            List <int> jsons = new List <int>();
            string     temp  = str;
            int        shift = 0;

            while (true)
            {
                var ind1 = temp.IndexOf("ajax.preload");
                temp = temp.Substring(ind1 + 5);

                if (ind1 == -1)
                {
                    break;
                }
                jsons.Add(ind1 + shift);
                shift += ind1 + 5;
            }

            List <string> jsonRefs = new List <string>();

            foreach (var ind1 in jsons)
            {
                int           brctcnt   = 0;
                int           brctcnt2  = 0;
                bool          start     = false;
                bool          ajaxStart = false;
                StringBuilder sbb       = new StringBuilder();
                int?          arrStart  = null;
                for (int i2 = ind1; i2 < str.Length; i2++)

                {
                    if (str[i2] == '(')
                    {
                        brctcnt2++; ajaxStart = true;
                    }
                    if (ajaxStart)
                    {
                        if (str[i2] == '[')
                        {
                            if (arrStart == null)
                            {
                                arrStart = i2;
                            }
                            brctcnt++; start = true;
                        }
                    }

                    if (str[i2] == ']')
                    {
                        brctcnt--;
                    }
                    if (str[i2] == ')')
                    {
                        brctcnt2--;
                    }
                    if (start)
                    {
                        sbb.Append(str[i2]);
                    }
                    if (brctcnt == 0 && start)
                    {
                        break;
                    }
                    if (brctcnt2 == 0 && ajaxStart)
                    {
                        break;
                    }
                }
                if (sbb.Length > 0 && arrStart != null)
                {
                    var          sub       = str.Substring(arrStart.Value);
                    byte[]       byteArray = Encoding.ASCII.GetBytes(sub);
                    MemoryStream stream    = new MemoryStream(byteArray);

                    var  rdr       = new StreamReader(stream);
                    var  rdr2      = new JsonTextReader(rdr);
                    bool fetchNext = false;
                    try
                    {
                        while (rdr2.Read())
                        {
                            if (rdr2.ValueType == typeof(string))
                            {
                                var str2 = (string)rdr2.Value;

                                if (rdr2.TokenType == JsonToken.PropertyName)
                                {
                                    if (str2 == "w_src" || str2 == "z_src")
                                    {
                                        fetchNext = true;
                                    }
                                }
                                else
                                {
                                    if (fetchNext)
                                    {
                                        jsonRefs.Add(str2);
                                        fetchNext = false;
                                    }
                                }
                            }
                        }
                    }
                    catch (JsonException ex)
                    {
                    }

                    /*JArray o1 = JArray.Parse(sbb.ToString()); ;
                     *
                     * WalkNode(o1, n =>
                     * {
                     *  JToken token = n["w_src"];
                     *  if (token != null && token.Type == JTokenType.String)
                     *  {
                     *      string wsrc = token.Value<string>();
                     *      jsonRefs.Add(wsrc);
                     *  }
                     *  token = n["z_src"];
                     *  if (token != null && token.Type == JTokenType.String)
                     *  {
                     *      string zsrc = token.Value<string>();
                     *      jsonRefs.Add(zsrc);
                     *  }
                     * });*/
                }
            }


            var pi = new HttpPageInfo();

            pi.Uri = _uri;
            Infos.Add(pi);
            //richTextBox2.Text = webBrowser1.DocumentText;


            var list       = Stuff.ParseHtmlItems(str, "<meta", "/>");
            var list2      = Stuff.ParseHtmlItems(str, "<a", "/a>");
            var list3      = Stuff.ParseHtmlItems(str, "<img", ">");
            int totalLinks = 0;
            var allLinks   = jsonRefs.Union(list).Union(list2).Union(list3).ToArray();

            foreach (var item in allLinks)
            {
                if (!item.Contains("http"))
                {
                    continue;
                }
                var ar1 = item.Split(new char[] { ' ', '\"' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                var ww  = ar1.Where(z => z.Contains("jpg") || z.Contains("png") || z.Contains("gif"));

                foreach (var _fr in ww)
                {
                    var fr = _fr;
                    try
                    {
                        var ind1 = fr.IndexOf("http");
                        if (ind1 > 0)
                        {
                            fr = fr.Substring(ind1);
                        }
                        string end = ".jpg";
                        if (fr.Contains("png"))
                        {
                            end = "png";
                        }
                        if (fr.Contains("gif"))
                        {
                            end = "gif";
                        }

                        var ind2 = fr.IndexOf(end);
                        fr = fr.Substring(0, ind2 + end.Length);

                        pi.Links.Add(new HttpPageInfo()
                        {
                            Uri = fr
                        });
                        totalLinks++;
                        listView2.Invoke((Action)(() =>
                        {
                            listView2.Items.Add(new ListViewItem(fr)
                            {
                                Tag = fr
                            });
                        }));
                        links++;
                        using (WebClient wc = new WebClient())
                        {
                            var uri = new Uri(fr);
                            if (strongNameSkip)
                            {
                                var nm = Path.Combine(saveTarget, uri.Segments.Last());
                                if (File.Exists(nm))
                                {
                                    skipped++;
                                    continue;
                                }
                            }
                            var data = wc.DownloadData(fr);
                            if (data.Length >= 0)
                            {
                                MemoryStream ms = new MemoryStream(data);
                                if (showPics)
                                {
                                    var img = Image.FromStream(ms);
                                    listView2.Invoke((Action)(() =>
                                    {
                                        pictureBox1.Image = img;
                                    }));
                                }
                                ms.Seek(0, SeekOrigin.Begin);
                                var hash = Stuff.CalcMD5(ms);
                                if (md5cache.Add(hash))
                                {
                                    var fp = Path.Combine(saveTarget, uri.Segments.Last());
                                    if (File.Exists(fp))
                                    {
                                        throw new Exception("hash not found, but file exist");
                                    }

                                    if (!useSizeFilter || ((data.Length / 1024) > sizeFilterKb))
                                    {
                                        saved++;
                                        File.WriteAllBytes(fp, data);
                                    }
                                    else
                                    {
                                        skipped++;
                                    }
                                    /*File.WriteAllBytes(Path.Combine(textBox1.Text, DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Second + ".png"), data);*/
                                    //img.Save(Path.Combine(textBox1.Text, DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Second + ".png"));
                                }
                                else
                                {
                                    skipped++;
                                }

                                ms.Dispose();
                            }
                        }


                        break;
                    }
                    catch (Exception ex)
                    {
                        errors++;
                        listView3.Invoke((Action)(() =>
                        {
                            listView3.Items.Add(new ListViewItem(new string[] { fr, ex.Message })
                            {
                                Tag = fr + ";" + ex
                            });
                        }));
                    }
                }
            }

            if (totalLinks == 0)
            {
                listView3.Invoke((Action)(() =>
                {
                    listView3.Items.Add(new ListViewItem(new string[] { "no links: " + _uri })
                    {
                        Tag = _uri, BackColor = Color.Yellow
                    });
                }));
            }
        }
Ejemplo n.º 20
0
        public static void LoadSettings()
        {
            if (!File.Exists("settings.xml"))
            {
                return;
            }
            var findex = new FileIndex()
            {
                FileName = "settings.xml", RootPath = Application.StartupPath
            };

            using (FileStream fs = new FileStream("settings.xml", FileMode.Open, FileAccess.Read))
            {
                findex.Load(fs, new DirectoryInfoWrapper(new DirectoryInfo(Application.StartupPath)), "settings.xml");
            }

            FileIndexes.Add(findex);

            var s  = XDocument.Load("settings.xml");
            var fr = s.Descendants("settings").First();

            Stuff.PasswordHash = fr.Attribute("password").Value;
            foreach (var descendant in s.Descendants("path"))
            {
                RecentPathes.Add(descendant.Value);
            }

            List <DirectoryEntry> direntries  = new List <DirectoryEntry>();
            List <FileEntry>      fileentries = new List <FileEntry>();

            //#region load directory and files entries
            //var entries = s.Descendants("entries").First();
            //foreach (var item in entries.Descendants("directory"))
            //{
            //    var id = int.Parse(item.Attribute("id").Value);
            //    var path = item.Value;
            //    //var dir = new DirectoryInfo(path);
            //    //path = dir.Parent.GetDirectories(dir.Name).First().FullName;
            //    direntries.Add(new DirectoryEntry() { Id = id, Path = path });
            //}
            //foreach (var item in entries.Descendants("file"))
            //{
            //    var id = int.Parse(item.Attribute("id").Value);
            //    var dirId = int.Parse(item.Attribute("dirId").Value);
            //    var name = item.Value;

            //    var dir = direntries.First(z => z.Id == dirId);
            //    //var path = Path.Combine(dir.Path, name);
            //    //var diri = new DirectoryInfo(dir.Path);
            //    //name = diri.GetFiles(name).First().Name;

            //    fileentries.Add(new FileEntry() { Id = id, Directory = dir, Name = name });
            //}
            //#endregion


            //#region meta

            //var metas = s.Descendants("meta").FirstOrDefault();
            //if (metas != null)
            //{
            //    foreach (var item in metas.Descendants("file"))
            //    {
            //        var fid = int.Parse(item.Attribute("fileId").Value);
            //        var f = fileentries.First(z => z.Id == fid);
            //        Stuff.MetaInfos.Add(new FileMetaInfo() { File = new FileInfoWrapper(new FileInfo(f.FullName)) });
            //        var minf = Stuff.MetaInfos.Last();

            //        foreach (var kitem in item.Descendants())
            //        {
            //            if (kitem.Name == "keywordsMetaInfo")
            //            {
            //                minf.Infos.Add(new KeywordsMetaInfo() { Parent = minf, Keywords = kitem.Value });
            //            }

            //        }

            //    }
            //}
            //#endregion
            foreach (var descendant in s.Descendants("tab"))
            {
                var hint   = descendant.Attribute("hint").Value;
                var owner  = descendant.Attribute("owner").Value;
                var path   = descendant.Attribute("path").Value;
                var filter = descendant.Attribute("filter").Value;

                var tab = new TabInfo()
                {
                    Filter = filter, Path = path, Hint = hint
                };
                tab.Owner = owner;
                Stuff.AddTab(tab);
            }

            foreach (var descendant in s.Descendants("library"))
            {
                var name = descendant.Attribute("name").Value;
                var path = descendant.Attribute("path").Value;
                Stuff.Libraries.Add(new FilesystemLibrary()
                {
                    Name = name, BaseDirectory = new DirectoryInfoWrapper(path)
                });
            }

            foreach (var descendant in s.Descendants("hotkey"))
            {
                var path    = descendant.Attribute("path").Value;
                var enabled = bool.Parse(descendant.Attribute("enabled").Value);
                var key     = (Keys)Enum.Parse(typeof(Keys), descendant.Attribute("key").Value);
                Stuff.Hotkeys.Add(new HotkeyShortcutInfo()
                {
                    IsEnabled = enabled, Hotkey = key, Path = path
                });
            }

            foreach (var descendant in s.Descendants("shortcut"))
            {
                var name = descendant.Attribute("name").Value;

                if (descendant.Attribute("type") != null)
                {
                    var tp = descendant.Attribute("type").Value;
                    switch (tp)
                    {
                    case "url":
                        var url = descendant.Element("url").Value;
                        Stuff.Shortcuts.Add(new UrlShortcutInfo(name, url));
                        break;

                    case "cmd":
                        var    wd   = descendant.Attribute("workdir").Value;
                        string args = null;
                        if (descendant.Element("args") != null)
                        {
                            args = descendant.Element("args").Value;
                        }

                        string appName = null;
                        if (descendant.Element("app") != null)
                        {
                            appName = descendant.Element("app").Value;
                        }
                        Stuff.Shortcuts.Add(new CmdShortcutInfo(name, args, wd, appName));
                        break;
                    }
                }
                else
                {
                    var path = descendant.Attribute("path").Value;
                    Stuff.Shortcuts.Add(new AppShortcutInfo(path, name));
                }
            }

            //foreach (var descendant in s.Descendants("tag"))
            //{
            //    var name = descendant.Attribute("name").Value;

            //    string flags = "";
            //    if (descendant.Attribute("flags") != null) { flags = descendant.Attribute("flags").Value; }

            //    var tag = new TagInfo() { Name = name, IsHidden = flags.Contains("hidden") };

            //    var snms = descendant.Descendants("synonym");
            //    foreach (var item in snms)
            //    {
            //        tag.Synonyms.Add(item.Value.Trim());
            //    }

            //    Stuff.Tags.Add(tag);
            //    foreach (var item in descendant.Descendants("file"))
            //    {
            //        var arr1 = item.Attribute("id").Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
            //        foreach (var aitem in arr1)
            //        {
            //            var ff = fileentries.First(z => z.Id == aitem);
            //            tag.AddFile(new FileInfoWrapper(ff.FullName));
            //        }
            //    }
            //}

            foreach (var descendant in s.Descendants("fileContextMenuItem"))
            {
                var    title   = descendant.Attribute("title").Value;
                var    appName = descendant.Attribute("appName").Value;
                string args    = null;
                if (descendant.Element("arguments") != null)
                {
                    args = descendant.Element("arguments").Value;
                }
                var f = new FileContextMenuItem()
                {
                    Title = title, AppName = appName, Arguments = args
                };
                Stuff.FileContextMenuItems.Add(f);
            }
            foreach (var descendant in s.Descendants("site"))
            {
                var path = descendant.Value;
                var f    = new OfflineSiteInfo()
                {
                    Path = path
                };
                Stuff.OfflineSites.Add(f);
            }
            var root = s.Descendants("bookmarks").First();

            LoadBookmarks(root);
        }
Ejemplo n.º 21
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();
        }
Ejemplo n.º 22
0
        public void BuildIndex()
        {
            var grp = StreamWrapper.StaticRequests.GroupBy(z => z.Host).ToArray();

            List <WebIndexItem> Roots = new List <WebIndexItem>();

            foreach (var item in grp)
            {
                Roots.Add(new WebIndexItem()
                {
                    Name = item.Key
                });
                var           zz    = item.ToArray().Select(z => z.Text).ToArray();
                List <string> sstrs = new List <string>();
                foreach (var zitem in zz)
                {
                    var u = zitem.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1];
                    sstrs.Add(u);
                }
                sstrs = sstrs.OrderBy(z => z).ToList();
                foreach (var sitem in sstrs)
                {
                    var str2 = sitem.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    CreatePath(Roots.Last(), str2);
                }

                foreach (var aitem in item.ToArray())
                {
                    var u    = aitem.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[1];
                    var str2 = u.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    GetByPath(Roots.Last(), str2).Request = aitem;
                }
            }

            foreach (var item in Roots)
            {
                item.CaclSize();
            }

            treeListView1.GridLines       = true;
            treeListView1.CanExpandGetter = (z) =>
            {
                if (z is WebIndexItem ww)
                {
                    return(ww.Childs.Any());
                }
                return(false);
            };

            treeListView1.ChildrenGetter = (z) =>
            {
                if (z is WebIndexItem ww)
                {
                    return(ww.Childs);
                }
                return(null);
            };


            (treeListView1.Columns[1] as OLVColumn).TextAlign    = HorizontalAlignment.Right;
            (treeListView1.Columns[1] as OLVColumn).AspectGetter = (x) =>
            {
                return(Stuff.GetUserFriendlyFileSize((x as WebIndexItem).Size));
            };
            treeListView1.SetObjects(Roots.OrderBy(z => z.Name));
        }
Ejemplo n.º 23
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            gr.SmoothingMode = SmoothingMode.AntiAlias;

            var pos = pictureBox1.PointToClient(Cursor.Position);

            gr.Clear(Color.White);
            gr.ResetTransform();
            //var gp=GetSector(45, 135, 100, 150);
            //   gr.DrawPath(Pens.Black, gp);

            if (ready /* && false*/)
            {
                hovered = null;
                var dist = Math.Sqrt(Math.Pow(pos.X - pictureBox1.Width / 2, 2) + Math.Pow(pos.Y - pictureBox1.Height / 2, 2));
                if (dist < radb)
                {
                    hovered = Root;
                }
                var ang = Math.Atan2(pos.Y - pictureBox1.Height / 2, pos.X - pictureBox1.Width / 2) * 180f / Math.PI;
                if (ang < 0)
                {
                    ang += 360f;
                }
                foreach (var item in Items)
                {
                    if (dist >= item.R1 && dist <= item.R2 && ang >= item.StartAng && ang <= item.EndAng)
                    {
                        hovered = item;
                    }
                }
                gr.DrawString((Root as ScannerDirInfo).GetDirFullName(), new Font("Arial", 12), Brushes.Black, 5, 5);
                if (hovered != null)
                {
                    gr.DrawString(hovered.Name, new Font("Arial", 12), Brushes.Black, 5, 25);
                    gr.DrawString(Stuff.GetUserFriendlyFileSize(hovered.Size), new Font("Arial", 12), Brushes.Black, 5, 45);
                }


                gr.TranslateTransform(bmp.Width / 2, bmp.Height / 2);


                if (Root == hovered)
                {
                    gr.FillEllipse(Brushes.Green, -radb, -radb, 2 * radb, 2 * radb);
                }
                else
                {
                    gr.FillEllipse(Brushes.Violet, -radb, -radb, 2 * radb, 2 * radb);
                }
                gr.DrawEllipse(Pens.Black, -radb, -radb, 2 * radb, 2 * radb);
                var sz = Stuff.GetUserFriendlyFileSize(Root.Size);
                var ff = new Font("Arial", 12);
                var ms = gr.MeasureString(sz, ff);

                gr.DrawString(sz, ff, Brushes.White, -ms.Width / 2, 0);

                sz = Root.Name;
                ms = gr.MeasureString(sz, ff);

                gr.DrawString(sz, ff, Brushes.White, -ms.Width / 2, -ms.Height);
                DrawLayer(gr, Root, radb, radb + radInc, 0, 360);
            }

            pictureBox1.Image = bmp;
        }
Ejemplo n.º 24
0
 private void button2_Click(object sender, EventArgs e)
 {
     Stuff.Warning("not implemented");
 }
Ejemplo n.º 25
0
        public void Load(Stream st, IDirectoryInfo root, string fname)
        {
            FileName = fname;
            RootPath = root.FullName;
            var s  = XDocument.Load(st);
            var fr = s.Descendants("settings").First();

            List <DirectoryEntry> direntries = new List <DirectoryEntry>();

            #region load directory and files entries
            var entries = s.Descendants("entries").First();
            foreach (var item in entries.Descendants("directory"))
            {
                var id   = int.Parse(item.Attribute("id").Value);
                var path = item.Value;
                //var dir = new DirectoryInfo(path);
                //path = dir.Parent.GetDirectories(dir.Name).First().FullName;

                direntries.Add(new DirectoryEntry()
                {
                    Id = id, Path = Path.Combine(root.FullName, path)
                });
            }
            foreach (var item in entries.Descendants("file"))
            {
                var id    = int.Parse(item.Attribute("id").Value);
                var dirId = int.Parse(item.Attribute("dirId").Value);
                var name  = item.Value;

                var dir = direntries.First(z => z.Id == dirId);
                //var path = Path.Combine(dir.Path, name);
                //var diri = new DirectoryInfo(dir.Path);
                //name = diri.GetFiles(name).First().Name;

                _fileEntries.Add(new FileEntry()
                {
                    Id = id, Directory = dir, Name = name
                });
            }
            #endregion


            #region meta

            var metas = s.Descendants("meta").FirstOrDefault();
            if (metas != null)
            {
                foreach (var item in metas.Descendants("file"))
                {
                    var fid = int.Parse(item.Attribute("fileId").Value);
                    var f   = _fileEntries.First(z => z.Id == fid);
                    Stuff.MetaInfos.Add(new FileMetaInfo()
                    {
                        File = new FileInfoWrapper(new FileInfo(f.FullName))
                    });
                    var minf = Stuff.MetaInfos.Last();

                    foreach (var kitem in item.Descendants())
                    {
                        if (kitem.Name == "keywordsMetaInfo")
                        {
                            minf.Infos.Add(new KeywordsMetaInfo()
                            {
                                Parent = minf, Keywords = kitem.Value
                            });
                        }
                    }
                }
            }
            #endregion


            foreach (var descendant in s.Descendants("tag"))
            {
                var name = descendant.Attribute("name").Value;

                string flags = "";
                if (descendant.Attribute("flags") != null)
                {
                    flags = descendant.Attribute("flags").Value;
                }

                var tag = new TagInfo()
                {
                    Name = name, IsHidden = flags.Contains("hidden")
                };

                var snms = descendant.Descendants("synonym");
                foreach (var item in snms)
                {
                    tag.Synonyms.Add(item.Value.Trim());
                }

                tag = Stuff.AddTag(tag);
                foreach (var item in descendant.Descendants("file"))
                {
                    var arr1 = item.Attribute("id").Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
                    foreach (var aitem in arr1)
                    {
                        var ff = _fileEntries.First(z => z.Id == aitem);
                        tag.AddFile(new FileInfoWrapper(ff.FullName), false);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            /*if (checkBox2.Checked)
             * {
             *  gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
             * }
             * else
             * {
             *  gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
             * }*/

            int       gap  = 30;
            int       min  = Math.Min(bmp.Width, bmp.Height);
            var       cx   = bmp.Width / 2;
            var       cy   = bmp.Height / 2;
            var       rad0 = (min / 2) - gap;
            Rectangle rect = new Rectangle(cx - rad0, cy - rad0, rad0 * 2, rad0 * 2);

            //check hover
            var pos   = pictureBox1.PointToClient(Cursor.Position);
            var atan2 = Math.Atan2(pos.Y - cy, pos.X - cx) * 180f / Math.PI;

            var dist = Math.Sqrt(Math.Pow(cx - pos.X, 2) + Math.Pow(cy - pos.Y, 2));


            List <ReportSectorInfo> sectors = Sectors.ToList();

            if (checkBox3.Checked)
            {
                #region remove small sectors
                List <ReportSectorInfo> todel = new List <ReportSectorInfo>();
                long totale = 0;

                var avg = collapseTreshold;
                for (int i = sectors.Count - 1; i >= 0; i--)
                {
                    totale += sectors[i].Length;
                    var perc1 = (float)totale / TotalLen;
                    todel.Add(sectors[i]);
                    if (sectors[i].Percentage > avg)
                    {
                        break;
                    }
                }
                if (todel.Count > 1)
                {
                    foreach (var item in todel)
                    {
                        sectors.Remove(item);
                    }

                    sectors.Add(new ReportSectorInfo()
                    {
                        Length = totale, Name = ".other sectors", Percentage = totale / (float)TotalLen
                    });
                }
            }
            #endregion ;


            if (atan2 < 0)
            {
                atan2 += 360;
            }

            atan2 %= 360;
            float sang = 0;

            hovered = null;
            if (dist < rad0)
            {
                foreach (var item in sectors)
                {
                    float eang = sang + item.Angle;
                    if (atan2 > sang && atan2 < eang)
                    {
                        hovered = item;
                        break;
                    }
                    sang = eang;
                }
            }
            gr.Clear(Color.White);
            sang = 0;

            foreach (var item in sectors)
            {
                if (hovered == item)
                {
                    gr.FillPie(Brushes.Red, rect, sang, item.Angle);
                }
                else
                {
                    if (item.Tag == CurrentDirectory)
                    {
                        gr.FillPie(Brushes.Yellow, rect, sang, item.Angle);
                    }
                    else
                    {
                        if (item.Tag == null)
                        {
                            gr.FillPie(Brushes.Blue, rect, sang, item.Angle);
                        }
                        else
                        {
                            gr.FillPie(Brushes.Green, rect, sang, item.Angle);
                        }
                    }
                }

                sang += item.Angle;
            }

            sang = 0;
            foreach (var item in sectors)
            {
                gr.DrawPie(Pens.Black, rect, sang, item.Angle);
                sang += item.Angle;
            }
            sang = 0;
            var font = new Font("Arial", 10);
            foreach (var item in sectors)
            {
                float eang = sang + item.Angle;

                var shift = 20;
                var ang   = sang + (eang - sang) / 2;
                var tx    = cx + (float)((rad0 + shift) * Math.Cos(ang * Math.PI / 180f));
                var ty    = cy + (float)((rad0 + shift) * Math.Sin(ang * Math.PI / 180f));
                var ms    = gr.MeasureString(item.Text, font);

                if (checkBox1.Checked && (item.Percentage * 100) > collapseTreshold)
                {
                    var tx1 = cx + (float)((rad0 / 2) * Math.Cos(ang * Math.PI / 180f));
                    var ty1 = cy + (float)((rad0 / 2) * Math.Sin(ang * Math.PI / 180f));
                    int ww1 = 6;


                    gr.DrawLine(Pens.Black, tx1, ty1, tx, ty);
                    gr.FillEllipse(new SolidBrush(Color.FromArgb(180, Color.Yellow)), tx1 - ww1, ty1 - ww1, ww1 * 2, ww1 * 2);
                    gr.DrawEllipse(Pens.Black, tx1 - ww1, ty1 - ww1, ww1 * 2, ww1 * 2);
                    gr.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), tx - 2, ty, ms.Width + 4, ms.Height);
                    gr.DrawRectangle(Pens.Black, tx - 2, ty, ms.Width + 4, ms.Height);
                    gr.DrawString(item.Text, font, Brushes.Black, tx, ty);
                }

                sang = eang;

                if (hovered == item)
                {
                    float         sx      = pos.X + 10;
                    float         sy      = pos.Y;
                    List <string> strings = new List <string>();
                    strings.Add(item.Name);
                    strings.Add(Stuff.GetUserFriendlyFileSize(item.Length));
                    strings.Add((item.Percentage * 100).ToString("F") + "%");
                    var mss  = strings.Select(z => gr.MeasureString(z, font)).ToArray();
                    var wmax = mss.Max(z => z.Width);
                    var hmax = mss.Max(z => z.Height);
                    if (pos.X > (bmp.Width - wmax))
                    {
                        sx = pos.X - wmax;
                    }
                    if (pos.Y > (bmp.Height - hmax * 3))
                    {
                        sy = pos.Y - hmax * 3;
                    }
                    gr.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), sx, sy, wmax, hmax * 3);
                    gr.DrawRectangle(Pens.Black, sx, sy, wmax, hmax * 3);
                    for (int i = 0; i < strings.Count; i++)
                    {
                        gr.DrawString(strings[i], font, Brushes.Black, sx, sy + hmax * i);
                    }
                }
            }
            pictureBox1.Image = bmp;
        }
Ejemplo n.º 27
0
 private void UnmountAllToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Stuff.UnmountAll();
     UpdateList();
 }
Ejemplo n.º 28
0
        public string[] EnumerateFiles()
        {
            var dir = new DirectoryInfoWrapper(BaseDirectory.FullName);

            return(Stuff.GetAllFiles(dir).Select(z => z.FullName).ToArray());
        }
Ejemplo n.º 29
0
        internal void Run(PackToIsoSettings stg)
        {
            packStg            = stg;
            label1.Text        = "Iso image path: " + stg.Path;
            Text               = "iso writing..";
            stg.ProgressReport = (now, total) =>
            {
                float f = now / (float)total;
                this.Invoke((Action)(() =>
                {
                    progressBar1.Value = (int)Math.Round(f * 100);
                }));
            };
            stg.AfterPackFinished = () =>
            {
                Stuff.Info("Pack to iso complete!");
                Close();
            };

            th = new Thread(() =>
            {
                this.Invoke((Action)(() =>
                {
                    label1.Text = "collecting files..";
                }));

                CDBuilder builder      = new CDBuilder();
                builder.ProgresReport  = stg.ProgressReport;
                List <IFileInfo> files = new List <IFileInfo>();
                foreach (var item in stg.Dirs)
                {
                    Stuff.GetAllFiles(item, files);
                }
                files.AddRange(stg.Files);

                if (stg.IncludeMeta)
                {
                    var mm = GenerateMetaXml(files.ToArray(), stg.Root);
                    builder.AddDirectory(".indx");
                    builder.AddFile(".indx\\meta.xml", Encoding.UTF8.GetBytes(mm));
                }
                builder.VolumeIdentifier = stg.VolumeId;
                if (stg.BeforePackStart != null)
                {
                    stg.BeforePackStart();
                }
                foreach (var item in stg.Dirs)
                {
                    PopulateFromFolder(builder, item, item.FullName);
                }

                foreach (var item in stg.Files)
                {
                    if (item is VirtualFileInfo)
                    {
                        var vfi = item as VirtualFileInfo;
                        builder.AddFile(item.FullName, vfi.FileInfo.FullName);
                    }
                    else
                    {
                        builder.AddFile(item.FullName, item.FullName);
                    }
                }
                this.Invoke((Action)(() =>
                {
                    label1.Text = "Building image: " + stg.Path;
                }));
                try
                {
                    builder.Build(stg.Path);
                    if (stg.AfterPackFinished != null)
                    {
                        stg.AfterPackFinished();
                    }
                }
                catch (ThreadAbortException ex)
                {
                    if (File.Exists(packStg.Path))
                    {
                        File.Delete(packStg.Path);
                    }
                }
            });
            th.IsBackground = true;
        }
Ejemplo n.º 30
0
        private void ToIsoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            List <TagInfo> tags = new List <TagInfo>();

            for (int i = 0; i < listView1.SelectedItems.Count; i++)
            {
                if (!(listView1.SelectedItems[i].Tag is TagInfo))
                {
                    continue;
                }
                tags.Add(listView1.SelectedItems[i].Tag as TagInfo);
            }

            if (tags.Count == 0)
            {
                return;
            }


            var vfs  = new VirtualFilesystem();
            var vdir = new VirtualDirectoryInfo(vfs);

            //vdir.FullName = "z:\\" + tag.Name;
            vdir.FullName = "z:\\";
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = "iso";
            sfd.Filter     = "iso images|*.iso";
            List <IFileInfo> flss = new List <IFileInfo>();

            foreach (var tag in tags)
            {
                flss.AddRange(tag.Files);
            }

            var gg = flss.GroupBy(z => z.FullName.ToLower()).ToArray();

            flss.Clear();
            foreach (var item in gg)
            {
                flss.Add(item.First());
            }

            var ord  = flss.GroupBy(z => z.FullName.ToLower()).ToArray();
            var ord2 = flss.GroupBy(z => z.Name.ToLower()).ToArray();

            if (ord2.Any(z => z.Count() > 1))
            {
                var fer = ord2.Where(z => z.Count() > 1).Sum(z => z.Count());
                Stuff.Warning(fer + " files has same names. Pack impossible");
                if (Stuff.Question("Open pack editor?") == DialogResult.Yes)
                {
                    PackEditor p = new PackEditor();
                    p.Init(flss);
                    p.MdiParent = mdi.MainForm;
                    p.Show();
                }
                return;
            }

            flss = ord.Select(z => z.First()).ToList();
            flss = flss.Where(z => z.Length > 0).ToList();

            vdir.ChildsFiles.AddRange(flss.Select(z => new VirtualFileInfo(z, vdir)
            {
                Directory = vdir
            }));

            vfs.Files = vdir.ChildsFiles.OfType <VirtualFileInfo>().ToList();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                PackToIsoSettings stg = new PackToIsoSettings();
                stg.Dirs.Add(vdir);
                stg.Path              = sfd.FileName;
                stg.IncludeMeta       = true;
                stg.Root              = vdir;
                stg.AfterPackFinished = () => { Stuff.Info("Pack complete!"); };
                if (tags.Count == 1)
                {
                    stg.VolumeId = tags.First().Name.Replace(' ', '_');
                }
                else
                {
                    stg.VolumeId = $"Volume[{tags.Count} tags]";
                }
                if (stg.VolumeId.Length > 32)
                {
                    stg.VolumeId = stg.VolumeId.Substring(0, 32);
                }
                Stuff.PackToIso(stg);
            }
        }