示例#1
0
        private void ChapterObjectArchiveWatcher_Event(object sender, FileSystemEventArgs e)
        {
            RunOnUiThread(() =>
            {
                switch (e.ChangeType)
                {
                case WatcherChangeTypes.Created:
                case WatcherChangeTypes.Deleted:
                    MangaCacheObject ExistingMangaCacheObject = MangaCacheObjects.FirstOrDefault(
                        _ => Equals(
                            _.MangaObject.MangaFileName(),
                            Path.GetDirectoryName(e.Name)));
                    if (!Equals(ExistingMangaCacheObject, null))
                    {
                        Int32 ExistingMangaCacheObjectIndex = ExistingMangaCacheObject.ChapterCacheObjects.FindIndex(_ => Equals(_.ArchiveFileName, Path.GetFileName(e.Name)));
                        if (ExistingMangaCacheObjectIndex >= 0)
                        {
                            ExistingMangaCacheObject.ChapterCacheObjects[ExistingMangaCacheObjectIndex].IsLocal = File.Exists(e.FullPath);
                        }
                    }
                    break;
                }

                Messenger.Instance.Send(e, "ChapterObjectArchiveWatcher");
            });
        }
示例#2
0
 private Boolean CanShowMangaCacheObjectDialog(MangaCacheObject MangaCacheObject)
 {
     if (Equals(MangaCacheObject, null))
     {
         return(false);
     }
     return(true);
 }
 private Boolean CanDeleteAsync(MangaCacheObject MangaCacheObject)
 {
     if (Equals(MangaCacheObject, null))
     {
         return(false);
     }
     return(true);
 }
 private Boolean CanRefresh(MangaCacheObject MangaCacheObject)
 {
     if (Equals(MangaCacheObject, null))
     {
         return(false);
     }
     return(true);
 }
 private Boolean CanEditAsync(MangaCacheObject MangaCacheObject)
 {
     if (Equals(MangaCacheObject, null))
     {
         return(false);
     }
     return(false);
     //return true;
 }
示例#6
0
        private Boolean FilterMangaCacheObject(object item)
        {
            MangaCacheObject MangaCacheObject = item as MangaCacheObject;

            if (String.IsNullOrWhiteSpace(SearchTerm))
            {
                return(true);
            }
            return(MangaCacheObject.MangaObject.IsNameMatch(SearchTerm));
        }
        private void DeleteAsync(MangaCacheObject MangaCacheObject)
        {
            String           SavePath     = Path.Combine(App.CORE.MANGA_ARCHIVE_DIRECTORY, MangaCacheObject.MangaObject.MangaArchiveName(App.CORE.MANGA_ARCHIVE_EXTENSION));
            MessageBoxResult msgboxResult = MessageBox.Show(String.Format("Are you sure you wish to delete \"{0}\"?", MangaCacheObject.MangaObject.Name), "Delete Manga?", MessageBoxButton.YesNo);

            if (Equals(msgboxResult, MessageBoxResult.Yes))
            {
                File.Delete(SavePath);
            }
        }
示例#8
0
        /// <summary>
        /// Warning, this will completely reload the cache.
        /// </summary>
        /// <returns>Time taken to load cache.</returns>
        private async Task <TimeSpan> FullMangaCacheObject()
        {
            Boolean   ErrorOccured = false;
            Stopwatch loadWatch    = Stopwatch.StartNew();

            await RenameSchema();

            String[] MangaArchivePaths = Directory.GetFiles(CORE.MANGA_ARCHIVE_DIRECTORY, CORE.MANGA_ARCHIVE_FILTER, SearchOption.TopDirectoryOnly);

            IEnumerable <Task <MangaCacheObject> > MangaCacheObjectTasksQuery =
                from MangaArchivePath in MangaArchivePaths
                // select UnsafeDispatcherLoadMangaCacheObjectAsync(MangaArchivePath);
                select DispatcherReloadMangaCacheObjectAsync(MangaArchivePath, true);

            List <Task <MangaCacheObject> > MangaCacheObjectTasks = MangaCacheObjectTasksQuery.ToList();

            await Current.Dispatcher.InvokeAsync(MangaCacheObjects.Clear);

            while (MangaCacheObjectTasks.Count > 0)
            {
                Task <MangaCacheObject> completedTask = await Task.WhenAny(MangaCacheObjectTasks);

                MangaCacheObjectTasks.Remove(completedTask);

                MangaCacheObject LoadedMangaCacheObject = await completedTask;
                if (!Equals(LoadedMangaCacheObject, null))
                {
                    await Current.Dispatcher.InvokeAsync(() => MangaCacheObjects.Add(LoadedMangaCacheObject));
                }
                else
                {
                    ErrorOccured = true;
                }
            }

            TimeSpan loadTime = loadWatch.Elapsed;

            loadWatch.Stop();
            if (ErrorOccured)
            {
                String[] ErrorMessageArray =
                {
                    "There was an error when attempting to load a manga on startup.",
                    "Please check the most recent log file for the full error."
                };
                String ErrorMessage = String.Join(Environment.NewLine, ErrorMessageArray);
                MessageBox.Show(
                    ErrorMessage,
                    "Error During Loading Manga!",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error,
                    MessageBoxResult.OK);
            }
            return(loadTime);
        }
        private void PreloadChapterObject(MangaObject MangaObject, ChapterObject ChapterObject)
        {
            if (!App.ContentDownloadManager.IsCacheKeyActive(App.ContentDownloadManager.CacheKey(MangaObject, ChapterObject)))
            {
                // Lookup MangaCacheObject and ChapterCacheObject
                MangaCacheObject MangaCacheObject = App.MangaCacheObjects.FirstOrDefault(mco => Equals(
                                                                                             mco.MangaObject.Name,
                                                                                             MangaObject.Name));
                ChapterCacheObject ChapterCacheObject = Equals(MangaCacheObject, null) ? null : MangaCacheObject.ChapterCacheObjects.FirstOrDefault(cco => Equals(
                                                                                                                                                        cco.ArchiveFileName,
                                                                                                                                                        ChapterObject.ChapterArchiveName(App.CORE.CHAPTER_ARCHIVE_EXTENSION)));

                // Start Download
                App.ContentDownloadManager.Download(
                    MangaObject,
                    ChapterObject,
                    Equals(ChapterCacheObject, null) ? null : ChapterCacheObject.DownloadProgressReporter);
            }
        }
 public MangaCacheObjectDetailViewModel(MangaCacheObject MangaCacheObject)
     : base(false)
 {
     this.MangaCacheObject = MangaCacheObject;
 }
示例#11
0
 private void ShowMangaCacheObjectDialog(MangaCacheObject MangaCacheObject)
 {
     MangaCacheObjectDialog.MangaCacheObjectDetail.MangaCacheObject = MangaCacheObject;
     MangaCacheObjectDialog.ShowDialog();
 }
示例#12
0
        private async Task <MangaCacheObject> UnsafeLoadMangaCacheObjectAsync(String ArchivePath)
        {
            try
            {
                MangaCacheObject MangaCacheObject = new MangaCacheObject();
                MangaCacheObject.ArchiveFileName = Path.GetFileName(ArchivePath);

                // Load BookmarkObject Data
                Stream BookmarkObjectStream = CORE.ZipManager.UnsafeRead(ArchivePath, typeof(BookmarkObject).Name);
                if (!Equals(BookmarkObjectStream, null))
                {
                    using (BookmarkObjectStream) { MangaCacheObject.BookmarkObject = BookmarkObjectStream.Deserialize <BookmarkObject>(SerializeType); }
                }

                // Load MangaObject Data
                Stream MangaObjectStream = CORE.ZipManager.UnsafeRead(ArchivePath, typeof(MangaObject).Name);
                if (!Equals(MangaObjectStream, null))
                {
                    using (MangaObjectStream) { MangaCacheObject.MangaObject = MangaObjectStream.Deserialize <MangaObject>(SerializeType); }
                }

                // Move archive to correct location if needed
                String CorrectArchivePath = Path.Combine(Path.GetDirectoryName(ArchivePath), MangaCacheObject.ArchiveFileName);
                if (!Equals(ArchivePath, CorrectArchivePath))
                {
                    File.Move(ArchivePath, CorrectArchivePath);
                    logger.Info(String.Format("MangaObject archive file was moved/renamed to '{0}'.", MangaCacheObject.ArchiveFileName));
                }

                // MangaObject update check
                Boolean VersionUpdated = false;
                if (!Equals(MangaCacheObject.MangaObject, null))
                {
                    UpdateMangaObjectVersion(MangaCacheObject.MangaObject, ref VersionUpdated);
                }
                if (VersionUpdated)
                {
                    logger.Info(String.Format("MangaObject version was updated for '{0}'.", MangaCacheObject.MangaObject.Name));
                    await CORE.ZipManager.WriteAsync(
                        CorrectArchivePath, typeof(MangaObject).Name,
                        MangaCacheObject.MangaObject.Serialize(SerializeType)).Retry(TimeSpan.FromMinutes(1));
                }

                // Load Cover Image
                IEnumerable <String> Entries = CORE.ZipManager.UnsafeGetEntries(CorrectArchivePath);
                LocationObject       SelectedCoverLocationObject = MangaCacheObject.MangaObject.SelectedCover();
                String CoverImageFileName = Path.GetFileName(SelectedCoverLocationObject.Url);
                if (!Entries.Contains(CoverImageFileName))
                {
                    // Try to download the missing cover;
                    ContentDownloadManager.DownloadCover(MangaCacheObject.MangaObject, SelectedCoverLocationObject);
                    // If the SelectedCover is not in the archive file select a new cover.
                    String Url = (from CoverLocation in MangaCacheObject.MangaObject.CoverLocations
                                  where Entries.Contains(Path.GetFileName(CoverLocation.Url))
                                  select CoverLocation.Url).FirstOrDefault();
                    if (!Equals(Url, null))
                    {
                        CoverImageFileName = Path.GetFileName(Url);
                    }
                }
                Stream CoverImageStream = CORE.ZipManager.UnsafeRead(CorrectArchivePath, CoverImageFileName);
                if (!Equals(CoverImageStream, null))
                {
                    using (CoverImageStream)
                    {
                        if (Equals(MangaCacheObject.CoverImage, null))
                        {
                            MangaCacheObject.CoverImage = new BitmapImage();
                        }

                        if (!Equals(MangaCacheObject.CoverImage.StreamSource, null))
                        {
                            MangaCacheObject.CoverImage.StreamSource.Close();
                            MangaCacheObject.CoverImage.StreamSource.Dispose();
                            MangaCacheObject.CoverImage.StreamSource = null;
                        }

                        MangaCacheObject.CoverImage.BeginInit();
                        MangaCacheObject.CoverImage.DecodePixelWidth = 300;
                        MangaCacheObject.CoverImage.CacheOption      = BitmapCacheOption.OnLoad;
                        MangaCacheObject.CoverImage.CreateOptions    = BitmapCreateOptions.PreservePixelFormat;
                        using (MangaCacheObject.CoverImage.StreamSource = CoverImageStream)
                        {
                            MangaCacheObject.CoverImage.EndInit();
                            MangaCacheObject.CoverImage.Freeze();
                        }
                        CoverImageStream.Close();
                    }
                }

                return(MangaCacheObject);
            }
            catch (Exception ex)
            {
                logger.Error(String.Format("Unable to read Manga Archive.\nFile: {0}", ArchivePath), ex);
                return(null);
            }
        }
示例#13
0
        private async void MangaObjectArchiveWatcher_Event(object sender, FileSystemEventArgs e)
        {
            if (Dispatcher.Thread == Thread.CurrentThread)
            {
                MangaCacheObject ExistingMangaCacheObject = MangaCacheObjects.FirstOrDefault(_ => Equals(_.ArchiveFileName, e.Name));
                switch (e.ChangeType)
                {
                case WatcherChangeTypes.Created:
                    if (Equals(ExistingMangaCacheObject, null))
                    {
                        MangaCacheObjects.Add(ExistingMangaCacheObject = new MangaCacheObject()
                        {
                            ArchiveFileName = e.Name
                        });
                    }
                    goto case WatcherChangeTypes.Changed;

                case WatcherChangeTypes.Changed:
                    // (Re)Cache if creaded or changed
                    if (!Equals(ExistingMangaCacheObject, null))
                    {
                        // If ExistingMangaCacheObject is null we are probably still loading.
                        MangaCacheObject ReloadedMangaCacheObject = await DispatcherReloadMangaCacheObjectAsync(e.FullPath, Equals(ExistingMangaCacheObject.CoverImage, null));

                        if (!Equals(ReloadedMangaCacheObject, null))
                        {
                            if (Equals(ExistingMangaCacheObject, null))
                            {
                                MangaCacheObjects.Add(ReloadedMangaCacheObject);
                            }
                            else
                            {
                                ExistingMangaCacheObject.Update(ReloadedMangaCacheObject);
                            }
                        }
                    }
                    break;

                case WatcherChangeTypes.Deleted:
                    // Reselect nearest neighbor after delete
                    Int32 ExistingIndex = MangaCacheObjects.IndexOf(ExistingMangaCacheObject);
                    if (ExistingIndex >= 0)
                    {
                        MangaCacheObjects.RemoveAt(ExistingIndex);
                    }

                    // If delete was the last item subtract from index
                    if (ExistingIndex >= MangaCacheObjects.Count)
                    {
                        --ExistingIndex;
                    }

                    Messenger.Instance.Send((ExistingIndex >= 0) ? MangaCacheObjects[ExistingIndex] : null, "SelectMangaCacheObject");
                    break;

                default:
                    break;
                }
                Messenger.Instance.Send(e, "MangaObjectArchiveWatcher");
            }
            else
            {
                Dispatcher.Invoke(DispatcherPriority.Send, new Action(() => MangaObjectArchiveWatcher_Event(sender, e)));
            }
        }
 private void Refresh(MangaCacheObject MangaCacheObject)
 {
     App.ContentDownloadManager.Download(MangaCacheObject.MangaObject, true, MangaCacheObject.DownloadProgressReporter);
 }
 private void EditAsync(MangaCacheObject MangaCacheObject)
 {
 }