private static void UpdateTotalProgress()
        {
            double totalDownloadSeconds = ItemsScheduledForDownload.Sum(p => p.Progress >= 0 ? p.GetOrGenerateVideoInfo().Result.Duration.TotalSeconds : 0);
            double totalProgress        = ItemsScheduledForDownload.Sum(p => p.Progress >= 0 ? p.Progress * (p.GetOrGenerateVideoInfo().Result.Duration.TotalSeconds / totalDownloadSeconds) : 0);

            TotalProgress?.Report(totalProgress);
        }
 /// <summary>
 /// Sets progress values
 /// </summary>
 /// <param name="itemProgress">Current progress</param>
 /// <param name="totalProgress">Total progress</param>
 public void SetProgress(ProgressInfo itemProgress, ProgressInfo totalProgress)
 {
     if (totalProgress.Done)
     {
         Close();
     }
     else
     {
         FileSourceInfo.SetText(string.Format(FILE_INFO_TEMPLATE, itemProgress.Description));
         FileProgress.SetProgress(itemProgress);
         TotalFilesCount.SetText("Files:" + $"{totalProgress.Count.ToString("#")}/{totalProgress.TotalCount.ToString("#")}".PadLeft(TotalFilesCount.Width - 6));
         TotalBytesCount.SetText("Bytes:" + $"{totalProgress.Proceded.ToString("#")}/{totalProgress.Total.ToString("#")}".PadLeft(TotalBytesCount.Width - 6));
         TotalProgress.SetProgress(totalProgress);
     }
 }
Example #3
0
        //Расчет прогресса
        private void Progress()
        {
            try
            {
                var percent = ++_count * 100 / _total;

                if (percent > 0 && percent != _percent)
                {
                    _percent = percent;

                    var endPeriod = (DateTime.Now - _startTime).TotalSeconds * 100 / _percent;

                    TotalProgress?.Invoke($"{_percent}% - {(_startTime.AddSeconds(endPeriod) - DateTime.Now).ToString("hh\\:mm\\:ss")}");
                }
            }
            catch (Exception e)
            {
                Exception?.Invoke(e.ToString());
            }
        }
Example #4
0
        private async void DownloadMp3Stream(FileRow fileRow)
        {
            fileRow.AddLog(string.Format("Zahájení stahování streamu: {0}", fileRow.UrlPage));

            var asyncDownloader = new AsyncDownloader();
            var output          = await asyncDownloader.GetData(fileRow.UrlMp3Download,
                                                                p =>
            {
                fileRow.Progress      = p.ProgressPercentage;
                fileRow.BytesReceived = p.BytesReceived;
                TotalProgress.UpdateProgress(Files);
            });

            if (output.DownloadOk)
            {
                SaveMp3(fileRow, output.Output);
            }
            else
            {
                fileRow.AddLog(string.Format("Chyba při stahování streamu: {0}.", output.Exception?.Message), FileRowState.Error);
            }
        }
Example #5
0
        private void SearchSpace_Loaded(object sender, RoutedEventArgs e)
        {
#if true
            bool loading = false;
            // Metadata 로딩
            Task.Run(async() => {
                if (IsMetadataLoaded || StartsLoading)
                {
                    return;
                }
                StartsLoading = true;
                Profiler.Push("Check metadata exists");
                if (!HitomiIndex.Instance.CheckMetadataExist() || Settings.Instance.Hitomi.AutoSync)
                {
//#if !DEBUG
//                    Koromo_Copy.Monitor.Instance.ControlEnable = true;
//                    Koromo_Copy.Monitor.Instance.Push("다운로드가 계속 진행되지 않는다면 이 창에서 Enter키를 눌러주세요");
//                    Koromo_Copy.Console.Console.Instance.Show();
//#endif
                    Profiler.Push("Start download metadata");
                    MainWindow.Instance.Fade_MiddlePopup(true, (string)FindResource("msg_download_metadata"));
#if true
                    //HitomiIndex.Instance.MetadataDownloadStatusEvent = UpdateDownloadText;
                    await HitomiIndex.Instance.DownloadMetadata();
#endif
                    MainWindow.Instance.FadeOut_MiddlePopup((string)FindResource("msg_download_data_complete"), false);
                    Koromo_Copy.Monitor.Instance.ControlEnable = false;
                }
                else
                {
                    Profiler.Push("Load metadata, hiddendata");
                    try
                    {
                        HitomiIndex.Instance.Load();
                        //MainWindow.Instance.Fade_MiddlePopup(false);
                    }
                    catch (Exception ex)
                    {
                        Koromo_Copy.Monitor.Instance.Push($"[Hitomi DataLoad] {ex.Message}\r\n{ex.StackTrace}");
                    }
                }
                if (Settings.Instance.Hitomi.UsingOriginalTitle)
                {
                    Profiler.Push("Check titles exists");
                    if (!HitomiTitle.Instance.CheckExist())
                    {
                        MainWindow.Instance.ModifyText_MiddlePopup((string)FindResource("msg_download_title"));
                        await HitomiTitle.Instance.DownloadTitle();
                        MainWindow.Instance.FadeOut_MiddlePopup((string)FindResource("msg_download_data_complete"), false);
                    }
                    HitomiTitle.Instance.Load();
                    HitomiTitle.Instance.ReplaceToOriginTitle();
                    Koromo_Copy.Monitor.Instance.Push($"Loaded titles: '{HitomiTitle.Instance.Count.ToString("#,#")}' articles.");
                }
                MainWindow.Instance.Fade_MiddlePopup(false);
                Profiler.Push("Rebuild tag data");
                HitomiIndex.Instance.RebuildTagData();
                if (HitomiIndex.Instance.metadata_collection != null)
                {
                    Koromo_Copy.Monitor.Instance.Push($"Loaded metadata: '{HitomiIndex.Instance.metadata_collection.Count.ToString("#,#")}' articles.");

                    if (Settings.Instance.Hitomi.UsingOptimization)
                    {
                        HitomiIndex.Instance.OptimizeMetadata();
                        Koromo_Copy.Monitor.Instance.Push($"Optimize metadata: '{HitomiIndex.Instance.metadata_collection.Count.ToString("#,#")}' articles.");
                    }
                }
                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                loading = true;
            }).ContinueWith(t =>
            {
                if ((IsMetadataLoaded || StartsLoading) && !loading)
                {
                    return;
                }
                TotalProgress.IsIndeterminate = false;
                TotalProgress.Value           = 0;
                IsMetadataLoaded = true;
                Storyboard sb    = TotalProgress.FindResource("FadeProgressStoryboard") as Storyboard;
                if (sb != null)
                {
                    sb.Completed += Sb_Completed;
                    BeginStoryboard(sb);
                }
                RecommendSpace.Instance.Update();
                if (Koromo_Copy.Version.RequireTidy(System.Reflection.Assembly.GetExecutingAssembly().Location))
                {
                    (new PatchNoteWindow()).Show();
                    //Process.Start("https://github.com/dc-koromo/koromo-copy/blob/master/Document/Update.md");
                }
                Task.Run(() => CheckUpdate()).ContinueWith((x) => ScriptManager.Instance.Initialization()).ContinueWith((x) => SettingViewScript.Instance.Init());
                Task.Run(() => DownloaderHelper.LoadOthersAsync());
                Task.Run(() => DPIB.Instance.Start());
            }, TaskScheduler.FromCurrentSynchronizationContext());
#endif
            Window w = Window.GetWindow(this);
            // 이거 지우면 디자이너 오류남
            if (w != null)
            {
                w.LocationChanged += (object obj, EventArgs args) =>
                {
                    var offset = AutoComplete.HorizontalOffset;
                    AutoComplete.HorizontalOffset = offset + 1;
                    AutoComplete.HorizontalOffset = offset;
                };
            }

            logic = new AutoCompleteLogic(SearchText, AutoComplete, AutoCompleteList);
        }
Example #6
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            var info   = args.Info;
            var canvas = args.Surface.Canvas;

            canvas.Clear();

            var lineSize     = (info.Width / TotalProgress) * 0.75f;
            var lineSizeHalf = lineSize * 0.5f;

            BackgroundPaint.StrokeWidth = lineSize;
            ForegroundPaint.StrokeWidth = lineSize;
            ForegroundPaint.StrokeCap   = SKStrokeCap.Round;

            var rect = new SKRect(lineSize, 0, info.Width - lineSize, info.Height);


            var textRect = new SKRect();

            TextPaint.MeasureText("0", ref textRect);

            var verticalSpace = rect.Height * 0.1f;

            var bottom = rect.Bottom - lineSizeHalf - (textRect.Height + verticalSpace);
            var top    = rect.Top + lineSizeHalf + (textRect.Height + verticalSpace);

            var regularHeight = (bottom - top) * 0.65f;

            var xPosInterval = rect.Width / (TotalProgress - 1);

            for (var i = 0; i < TotalProgress; i++)
            {
                var xPos = rect.Left + xPosInterval * i;

                // Draw Labels
                if (i == 0)
                {
                    // Start Label
                    const string progressText = "0";
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Bottom - 2,
                                    TextPaint);
                }
                else if (i == TotalProgress - 1)
                {
                    // End Label
                    var progressText = TotalProgress.ToString();
                    TextPaint.MeasureText(progressText, ref textRect);
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Bottom - 2,
                                    TextPaint);
                }

                if (i + 1 < Progress)
                {
                    // Draw Foreground
                    canvas.DrawLine(xPos, bottom - regularHeight, xPos, bottom, ForegroundPaint);
                }
                else if (i + 1 == Progress)
                {
                    // Draw Current Progress
                    canvas.DrawLine(xPos, top, xPos, bottom, ForegroundPaint);

                    TextPaint.Color = TextPaint.Color.WithAlpha(255);
                    var progressText = Progress.ToString();
                    TextPaint.MeasureText(progressText, ref textRect);
                    canvas.DrawText(progressText,
                                    XPosInsideBounds(xPos, textRect, info),
                                    rect.Top + textRect.Height,
                                    ActiveTextPaint);
                }
                else
                {
                    // Draw Background
                    canvas.DrawLine(xPos, bottom - regularHeight, xPos, bottom, BackgroundPaint);
                }
            }
        }
Example #7
0
 public ShellViewModel()
 {
     Files         = new ObservableCollection <FileRow>();
     TotalProgress = new TotalProgress();
 }