Ejemplo n.º 1
0
        private async void bStart_ClickAsync(object sender, EventArgs e)
        {
            if (cbIcon.Checked)
            {
                tvFs.ImageList = smallImageList;
            }
            else
            {
                tvFs.ImageList = null;
            }

            pbIndexing.Value = 0;
            listView1.Items.Clear();
            listView2.Items.Clear();
            tvFs.Nodes.Clear();
            tbPath.Enabled = false;
            bStart.Enabled = false;
            SetStatusMessage(StatusMessage.StartIndexing);
            indexor = new FileIndexor();
            await indexor.ListingDirectoryAsync(tbPath.Text);

            SetStatusMessage(StatusMessage.Enumerating);
            tbPath.Enabled = true;
            bStart.Enabled = true;
            await Task.Run(() => Processing());
        }
Ejemplo n.º 2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            FileIndexor fi = new FileIndexor();
            await fi.ListingDirectoryAsync(@"C:\");

            listing(fi);
        }
Ejemplo n.º 3
0
        private async void button1_Click_1Async(object sender, EventArgs e)
        {
            var         ss      = textBox1.Text.Split('|');
            FileIndexor indexor = new FileIndexor();
            await indexor.ListingDirectoryAsync(textBox2.Text);

            var x = indexor.GetDirectories();

            var line = 0;

            foreach (var f in x)
            {
                if (f.Contains(@"\packages"))
                {
                    continue;
                }
                var folder = Directory.GetFiles(f);
                foreach (var fn in folder)
                {
                    var extn = Path.GetExtension(fn).ToLower();
                    if (!ss.Contains(extn))
                    {
                        continue;
                    }
                    var cc = File.ReadLines(fn).Count();
                    line += cc;

                    ListView1.Items.Add(new ListViewItem(new string[]
                    {
                        fn, cc.ToString()
                    }));
                }
            }
            label4.Text = line + " 줄";
        }
Ejemplo n.º 4
0
        static void ProcessExtract()
        {
            var xxx = JsonConvert.DeserializeObject <List <EHentaiResultArticle> >(File.ReadAllText("ex-hentai-archive.json"));

            const string archive = @"E:\2019\e-archive";
            var          ix      = new FileIndexor();

            Task.Run(async() => await ix.ListingDirectoryAsync(archive)).Wait();

            var htmls = new List <string>();

            ix.Enumerate((string path, List <FileInfo> files) =>
            {
                files.ForEach(x => htmls.Add(x.FullName));
            });

            var result = new List <EHentaiResultArticle>();

            using (var progressBar = new Console.ConsoleProgressBar())
            {
                int x = 0;
                foreach (var html in htmls)
                {
                    var content = File.ReadAllText(html);
                    try
                    {
                        var exh = ExHentaiParser.ParseResultPageExtendedListView(content);
                        //Console.Instance.WriteLine("[GET] " + exh.Count + " Articles! - " + html);
                        result.AddRange(exh);
                        if (exh.Count != 25)
                        {
                            Console.Instance.WriteLine("[Miss] " + html);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Instance.WriteLine("[Fail] " + html);
                    }
                    x++;
                    progressBar.SetProgress(x / (float)htmls.Count * 100);
                }
            }


            JsonSerializer serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            Monitor.Instance.Push("Write file: ex-hentai-archive.json");
            using (StreamWriter sw = new StreamWriter(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ex-hentai-archive.json")))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, result);
                }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 로그를 복구하고, 기존 설정을 덮어씁니다.
        /// </summary>
        /// <param name="args"></param>
        static void ProcessRecoverLog(string[] args)
        {
            Console.Instance.WriteLine("This operation deletes existing log contents.");
            Console.Instance.Write("Are you sure to continue? yes or no) ");

            var res = System.Console.ReadLine();

            if (res != "yes")
            {
                Console.Instance.WriteLine("Process canceled.");
                return;
            }

            Console.Instance.WriteLine("Enumerating files...");

            var fi        = new FileIndexor();
            var file_list = new List <FileInfo>();

            fi.ListingDirectoryAsync(args[0]).Wait();
            fi.Enumerate((string path, List <FileInfo> files) =>
            {
                foreach (var iz in files)
                {
                    if (Path.GetExtension(iz.Name) == ".zip")
                    {
                        file_list.Add(iz);
                    }
                }
            });

            Console.Instance.WriteLine($"{file_list.Count.ToString("0,0")} zip files found!");
            file_list.Sort((x, y) => x.LastWriteTime.CompareTo(y.LastWriteTime));

            var rx = new Regex(@"^\[(\d+)\]");

            foreach (var file in file_list)
            {
                if (rx.Match(Path.GetFileNameWithoutExtension(file.Name)).Success)
                {
                    var id = rx.Match(Path.GetFileNameWithoutExtension(file.Name)).Groups[1].Value;
                    var md = HitomiLegalize.GetMetadataFromMagic(id);

                    if (!md.HasValue)
                    {
                        Console.Instance.WriteLine($"{id} article was not found!");
                        continue;
                    }

                    HitomiLog.Instance.AddArticle(HitomiLegalize.MetadataToArticle(md.Value), file.LastWriteTime);
                }
            }

            HitomiLog.Instance.Save();
        }
Ejemplo n.º 6
0
        private void listing(FileIndexor fi)
        {
            FileIndexorNode node = fi.GetRootNode();

            foreach (FileIndexorNode n in node.Nodes)
            {
                make_node(PathTree.Nodes, Path.GetFileName(n.Path.Remove(n.Path.Length - 1)));
                make_tree(n, PathTree.Nodes[PathTree.Nodes.Count - 1]);
            }
            foreach (FileInfo f in new DirectoryInfo(node.Path).GetFiles())
            {
                make_node(PathTree.Nodes, f.Name);
            }
        }
Ejemplo n.º 7
0
        private async void bOpen_ClickAsync(object sender, EventArgs e)
        {
            indexor = null;
            indexor = new FileIndexor();
            PathTree.Nodes.Clear();
            AvailableList.Items.Clear();

            Monitor.Instance.Push($"[Hitomi Explorer] Open directory '{tbPath.Text}'");
            await indexor.ListingDirectoryAsync(tbPath.Text);

            Monitor.Instance.Push($"[Hitomi Explorer] Complete open! DirCount={indexor.Count}");

            listing(indexor);
        }
Ejemplo n.º 8
0
        static void ProcessLoadDir(string[] args)
        {
            Console.Instance.GlobalTask.Add(Task.Run(async() =>
            {
                if (!Directory.Exists(args[0]))
                {
                    Console.Instance.WriteErrorLine($"'{args[0]}' is not valid directory name.");
                    return;
                }

                var indexor         = new FileIndexor();
                indexor.OnlyListing = true;
                await indexor.ListingDirectoryAsync(args[0]);

                dirs = indexor.GetDirectories();
            }));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 특정된 옵션에 따라 파일 또는 폴더를 나열합니다.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="recursive"></param>
        /// <param name="with_files"></param>
        static void ProcessDirectory(string[] args, bool recursive, bool with_files)
        {
            Console.Instance.GlobalTask.Add(Task.Run(async() =>
            {
                if (!Directory.Exists(args[0]))
                {
                    Console.Instance.WriteErrorLine($"'{args[0]}' is not valid directory name.");
                    return;
                }

                if (!recursive)
                {
                    foreach (DirectoryInfo d in new DirectoryInfo(args[0]).GetDirectories())
                    {
                        Console.Instance.WriteLine(d.FullName);
                    }

                    if (with_files)
                    {
                        foreach (FileInfo f in new DirectoryInfo(args[0]).GetFiles())
                        {
                            Console.Instance.WriteLine(f.FullName);
                        }
                    }
                }
                else
                {
                    var indexor = new FileIndexor();
                    await indexor.ListingDirectoryAsync(args[0]);

                    FileIndexorNode node = indexor.GetRootNode();
                    foreach (FileIndexorNode n in node.Nodes)
                    {
                        Console.Instance.WriteLine(n.Path);
                        internal_listing(n, with_files);
                    }
                    if (with_files)
                    {
                        foreach (FileInfo f in new DirectoryInfo(node.Path).GetFiles())
                        {
                            Console.Instance.WriteLine(f.FullName);
                        }
                    }
                }
            }));
        }
Ejemplo n.º 10
0
        private async void tbPath_KeyDownAsync(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.Handled = true;

                FileIndexor fi = new FileIndexor();
                await fi.ListingDirectoryAsync(tbPath.Text);

                StringBuilder builder = new StringBuilder();

                fi.Enumerate((x, y) =>
                {
                    if (!checkBox4.Checked)
                    {
                        x = x.Replace(fi.RootDirectory + '\\', "");
                    }
                    if (checkBox1.Checked)
                    {
                        builder.Append(x.TrimEnd('\\') + "\r\n");
                    }
                    if (checkBox3.Checked)
                    {
                        y.ForEach(z =>
                        {
                            if (!checkBox4.Checked)
                            {
                                builder.Append(z.FullName.Replace(fi.RootDirectory + '\\', "").TrimEnd('\\') + "\r\n");
                            }
                            else
                            {
                                builder.Append(z.FullName.TrimEnd('\\') + "\r\n");
                            }
                        });
                    }
                }, checkBox2.Checked);

                tbFileIndexing.Text = builder.ToString();
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 폴더를 옮깁니다.
        /// </summary>
        /// <param name="args"></param>
        static void ProcessMove(string[] args)
        {
            var overlap = new Dictionary <string, List <string> >();
            var valid   = new HashSet <string>();

            foreach (var dir in dirs)
            {
                var d = Path.GetFileName(Path.GetDirectoryName(dir));
                if (!overlap.ContainsKey(d))
                {
                    overlap.Add(d, new List <string>());
                }
                overlap[d].Add(dir);
                valid.Add(d);
            }

            var indexor = new FileIndexor();

            indexor.OnlyListing = true;
            Task.Run(async() => await indexor.ListingDirectoryAsync(args[0])).Wait();

            foreach (var dir in indexor.GetDirectories())
            {
                //if (Directory.GetDirectories(dir).Length == 0 && Directory.GetFiles(dir).Length == 0)
                //{
                //    Directory.Delete(dir);
                //    Console.Instance.WriteLine("[DELETE] " + dir);
                //    continue;
                //}

                var d = Path.GetFileName(Path.GetDirectoryName(dir));

                if (valid.Contains(d))
                {
                    if (overlap[d].Count == 1)
                    {
                        var del = true;
                        foreach (string fi in Directory.GetFiles(dir))
                        {
                            var filename = Path.GetFileName(fi);

                            if (File.Exists(Path.Combine(overlap[d][0], filename)))
                            {
                                Console.Instance.WriteLine("File already exists " + d + " " + filename);
                                if (new FileInfo(fi).Length <= new FileInfo(Path.Combine(overlap[d][0], filename)).Length * 1.1)
                                {
                                    Console.Instance.WriteLine("Same length " + new FileInfo(fi).Length);
                                    File.Delete(fi);
                                    Console.Instance.WriteLine("[DELETE FILE] " + fi);
                                    continue;
                                }
                                del = false;
                                continue;
                            }

                            File.Move(fi, Path.Combine(overlap[d][0], filename));
                            Console.Instance.WriteLine("[MOVE] " + fi + " => " + Path.Combine(overlap[d][0], filename));
                        }

                        if (del && Directory.GetDirectories(dir).Length == 0)
                        {
                            Directory.Delete(dir);
                            Console.Instance.WriteLine("[DELETE] " + dir);
                        }
                    }
                    else
                    {
                        Console.Instance.WriteLine("Cannot move " + d);
                    }
                }
                else
                {
                    Console.Instance.WriteLine("Not found " + d);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 디렉토리를 탐색하고 데이터베이스 파일을 생성합니다.
        /// </summary>
        /// <param name="path"></param>
        private async void ProcessPath(string path)
        {
            FileIndexor fi = new FileIndexor();
            await fi.ListingDirectoryAsync(path);

            string root_directory = fi.RootDirectory;

            Dictionary <string, ZipArtistsArtistModel> artist_dic = new Dictionary <string, ZipArtistsArtistModel>();

            foreach (var x in fi.Directories)
            {
                await Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                     delegate
                {
                    ProgressText.Text = x.Item1;
                }));

                Dictionary <string, HitomiJsonModel> article_data = new Dictionary <string, HitomiJsonModel>();
                DateTime last_access_time = DateTime.MinValue;
                DateTime craete_time      = DateTime.Now;
                foreach (var file in x.Item3)
                {
                    if (!file.FullName.EndsWith(".zip"))
                    {
                        continue;
                    }
                    var zipFile = ZipFile.Open(file.FullName, ZipArchiveMode.Read);
                    if (zipFile.GetEntry("Info.json") == null)
                    {
                        continue;
                    }
                    using (var reader = new StreamReader(zipFile.GetEntry("Info.json").Open()))
                    {
                        var json_model = JsonConvert.DeserializeObject <HitomiJsonModel>(reader.ReadToEnd());
                        article_data.Add(Path.GetFileName(file.FullName), json_model);
                    }
                    if (file.LastWriteTime < craete_time)
                    {
                        craete_time = file.LastWriteTime;
                    }
                    if (last_access_time < file.LastWriteTime)
                    {
                        last_access_time = file.LastWriteTime;
                    }
                }
                if (article_data.Count == 0)
                {
                    continue;
                }
                artist_dic.Add(x.Item1.Substring(root_directory.Length), new ZipArtistsArtistModel {
                    ArticleData = article_data, CreatedDate = craete_time.ToString(), LastAccessDate = last_access_time.ToString(), ArtistName = Path.GetFileName(Path.GetDirectoryName(x.Item1)), Size = (long)x.Item2
                });
            }

            model = new ZipArtistsModel();
            model.RootDirectory = root_directory;
            model.Tag           = path;
            model.ArtistList    = artist_dic.ToArray();
            var tick = DateTime.Now.Ticks;

            ZipArtistsModelManager.SaveModel($"zipartists-{Path.GetFileName(root_directory)}-{tick}.json", model);

            rate_filename = $"zipartists-{Path.GetFileName(root_directory)}-{tick}-rating.json";

            algorithm.Build(model);
            artist_list = artist_dic.ToList();
            elems.Clear();
            artist_list.ForEach(x => elems.Add(Tuple.Create(x, Tuple.Create(root_directory + x.Key, 0, false))));
            day_before = raws = elems;
            sort_data(align_column, align_row);

            await Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                 delegate
            {
                CollectStatusPanel.Visibility = Visibility.Collapsed;
                ArticleCount.Text = $"작가 {artist_dic.Count.ToString("#,#")}명";
                PageCount.Text = $"작품 {artist_list.Select(x => x.Value.ArticleData.Count).Sum().ToString("#,#")}개";
                max_page = artist_dic.Count / show_elem_per_page;
                initialize_page();
            }));

            stack_clear();
            stack_push();
        }
Ejemplo n.º 13
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!Addr.Text.EndsWith(".txt"))
            {
                PB.IsIndeterminate = true;
                FileIndexor fi = new FileIndexor();
                await fi.ListingDirectoryAsync(Addr.Text);

                PB.IsIndeterminate = false;

                file_list = new List <string>();
                fi.Enumerate((string path, List <FileInfo> files) =>
                {
                    foreach (var iz in files)
                    {
                        if (Path.GetExtension(iz.Name) == ".zip")
                        {
                            file_list.Add(iz.FullName);
                        }
                    }
                });

                append(file_list.Count.ToString("#,#") + "개의 Zip 파일이 검색됨");
            }
            else
            {
                var lls = File.ReadAllLines(Addr.Text);

                var pp = new List <Tuple <string, string> >();

                var rx = new Regex(@"^\[(\d+)\]");
                foreach (var article in lls)
                {
                    var f = Path.GetFileNameWithoutExtension(article);
                    if (rx.Match(Path.GetFileNameWithoutExtension(article)).Success)
                    {
                        var id     = rx.Match(System.IO.Path.GetFileNameWithoutExtension(article)).Groups[1].Value;
                        var artist = Path.GetFileName(Path.GetDirectoryName(article));

                        pp.Add(new Tuple <string, string>(id, artist));
                    }
                    else
                    {
                        append("[NO MATCH] " + article);
                    }
                }

                var articles = new List <HitomiArticle>();

                foreach (var p in pp)
                {
                    var aaa = HitomiLegalize.GetMetadataFromMagic(p.Item1);

                    if (!aaa.HasValue)
                    {
                        append("[NOT FOUND] " + p.Item1);
                        continue;
                    }

                    var xxx = HitomiLegalize.MetadataToArticle(aaa.Value);
                    xxx.Artists = new string[] { p.Item2 };
                    articles.Add(xxx);
                }

                await Task.Run(() =>
                {
                    int cnt = 0;
                    foreach (var at in articles)
                    {
                        try
                        {
                            var url       = HitomiCommon.GetImagesLinkAddress(at.Magic);
                            var imgs      = HitomiParser.GetImageLink(NetCommon.DownloadString(url));
                            at.ImagesLink = imgs;
                        }
                        catch
                        {
                            append("[FAIL DOWNLOAD] " + at.Magic);
                        }

                        cnt++;

                        Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                       delegate
                        {
                            PB.Value = cnt / (double)articles.Count * 100;
                        }));
                    }

                    int count = 0;

                    foreach (var ha in articles)
                    {
                        if (ha.ImagesLink == null)
                        {
                            continue;
                        }
                        var prefix = HitomiCommon.MakeDownloadDirectory(ha);
                        Directory.CreateDirectory(prefix);
                        DownloadSpace.Instance.RequestDownload(ha.Title,
                                                               ha.ImagesLink.Select(y => HitomiCommon.GetDownloadImageAddress(ha.Magic, y, ha.HasWebp[y], ha.HasWebp[y] || ha.Hashs[y].Length > 3 ? ha.Hashs[y] : "")).ToArray(),
                                                               ha.ImagesLink.Select(y => Path.Combine(prefix, y)).ToArray(),
                                                               Koromo_Copy.Interface.SemaphoreExtends.Default, prefix, ha);
                        count++;
                    }

                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        if (count > 0)
                        {
                            MainWindow.Instance.FadeOut_MiddlePopup($"{count}{FindResource("msg_download_start")}");
                        }
                        MainWindow.Instance.Activate();
                        MainWindow.Instance.FocusDownload();
                    }));
                });
            }
        }
Ejemplo n.º 14
0
 private void cb(string path)
 {
     fx = new FileIndexor(path);
 }