Пример #1
0
        public static void SaveModel(string filename, ZipArtistsModel model)
        {
            JsonSerializer serializer = new JsonSerializer();

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

            Monitor.Instance.Push($"Write file: {filename}");
            using (StreamWriter sw = new StreamWriter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename)))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, model);
                }
        }
        public void Build(ZipArtistsModel src)
        {
            tagdata_collection = new HitomiTagdataCollection();
            tagdata_collection.artist?.Clear();

            Dictionary<string, int> artist = new Dictionary<string, int>();
            
            src.ArtistList.Select(x => x.Value).Select(x => x.ArticleData.Select(y => y.Value)).ToList().ForEach(x => x.ToList().ForEach(article =>
            {
                if (article.Artists != null) article.Artists.ToList().ForEach(z => Add(artist, z));
            }));

            tagdata_collection.artist = artist.Select(x => new HitomiTagdata() { Tag = x.Key, Count = x.Value }).ToList();
            tagdata_collection.artist.Sort((a, b) => b.Count.CompareTo(a.Count));
            builded = true;
        }
Пример #3
0
        private async void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = sender as ListBoxItem;

            if (item.Tag.ToString() == "New")
            {
                var cofd = new CommonOpenFileDialog();
                cofd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                cofd.IsFolderPicker   = true;
                if (cofd.ShowDialog(this) == CommonFileDialogResult.Ok)
                {
                    CollectStatusPanel.Visibility = Visibility.Visible;
                    await Task.Run(() => ProcessPath(cofd.FileName));
                }
            }
            else if (item.Tag.ToString() == "Open")
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                ofd.Filter           = "데이터 파일 (*.json)|*.json";
                if (ofd.ShowDialog() == true)
                {
                    // 열기
                    try
                    {
                        model = ZipArtistsModelManager.OpenModel(ofd.FileName);

                        var raw = System.IO.Path.GetFileNameWithoutExtension(ofd.FileName);
                        rate_filename = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(ofd.FileName), raw + "-rating.json");

                        if (File.Exists(rate_filename))
                        {
                            rating_model = ZipArtistsModelManager.OpenRatingModel(rate_filename);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("옳바른 파일이 아닙니다!", "Zip Listing", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    bool offline = false;
                    if (!Directory.Exists(model.RootDirectory))
                    {
                        if (MessageBox.Show($"루트 디렉토리 \"{model.RootDirectory}\"를 찾을 수 없습니다! 디렉토리 위치가 변경되었다면 직접 루트 디렉토리를 수정해주세요!\r\n오프라인 모드로 열까요?", "Zip Listing", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
                        {
                            return;
                        }
                        offline = true;
                    }

                    algorithm.Build(model);
                    artist_list = model.ArtistList.ToList();

                    // 초기화
                    elems.Clear();
                    artist_list.ForEach(x => elems.Add(Tuple.Create(x, Tuple.Create(model.RootDirectory + x.Key, 0, offline))));
                    day_before = raws = elems;
                    sort_data(align_column, align_row);
                    ArticleCount.Text = $"작가 {artist_list.Count.ToString("#,#")}명";
                    PageCount.Text    = $"작품 {artist_list.Select(x => x.Value.ArticleData.Count).Sum().ToString("#,#")}개";
                    max_page          = artist_list.Count / show_elem_per_page;
                    initialize_page();
                    stack_clear();
                    stack_push();
                }
            }
            else if (item.Tag.ToString() == "Back")
            {
                stack_back();
            }
            else if (item.Tag.ToString() == "Forward")
            {
                stack_forward();
            }
            else if (item.Tag.ToString() == "Align")
            {
                var dialog = new ZipArtistsSorting(align_column, align_row);
                if ((bool)(await DialogHost.Show(dialog, "RootDialog")))
                {
                    int column = dialog.AlignColumnIndex;
                    int row    = dialog.AlignRowIndex;

                    if (column == align_column && row == align_row)
                    {
                        return;
                    }
                    sort_data(column, row);
                    align_column = column;
                    align_row    = row;
                    initialize_page();

                    stack_push();
                }
            }
            else if (item.Tag.ToString() == "Filter")
            {
                if (raws.Count == 0)
                {
                    return;
                }
                var dialog = new ZipArtistsFilter(raws.Select(x => DateTime.Parse(x.Item1.Value.LastAccessDate)).ToList(), starts, ends, show_bookmark);
                if ((bool)(await DialogHost.Show(dialog, "RootDialog")))
                {
                    if (dialog.StartDate.SelectedDate.HasValue)
                    {
                        starts = dialog.StartDate.SelectedDate;
                    }
                    if (dialog.EndDate.SelectedDate.HasValue)
                    {
                        ends = dialog.EndDate.SelectedDate.Value.AddMilliseconds(23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000 + 999);
                    }
                    if (dialog.ShowBookmark.IsChecked.HasValue)
                    {
                        show_bookmark = dialog.ShowBookmark.IsChecked.Value;
                    }
                    elems = day_before;
                    filter_data();
                    max_page = elems.Count / show_elem_per_page;
                    initialize_page();

                    stack_push();
                }
            }
            else if (item.Tag.ToString() == "Statistics")
            {
                if (artist_list == null || artist_list.Count == 0)
                {
                    return;
                }
                var dialog = new ZipArtistsStatistics(artist_list);
                await DialogHost.Show(dialog, "RootDialog");
            }
            else if (item.Tag.ToString() == "Tool")
            {
                var dialog = new ZipArtistsTool();
                await DialogHost.Show(dialog, "RootDialog");
            }
        }
Пример #4
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();
        }