public void RefreshReferenceLabel()
 {
     if (this.Reference != null)
     {
         if (this.Property == FileProperty.ContainsTag)
         {
             this.ReferenceLabel = LibraryOwner.GetCurrent()
                                   .Tags.GetTagValue((int)this.Reference)?.Name;
         }
         else if (this.Property.IsDate())
         {
             if (this.Property == FileProperty.DateTimeCreated ||
                 this.Property == FileProperty.DateTimeModified ||
                 this.Property == FileProperty.DateTimeRegistered)
             {
                 this.ReferenceLabel = ((DateTimeOffset)this.Reference).ToString("G");
             }
             else
             {
                 this.ReferenceLabel = ((DateTimeOffset)this.Reference).ToString("d");
             }
         }
         else if (this.Property == FileProperty.Size)
         {
             this.ReferenceLabel = FileSizeConverter.ConvertAuto((long)this.Reference);
         }
         else
         {
             this.ReferenceLabel = this.Reference.ToString();
         }
     }
 }
 public IEnumerable <SortSetting> GetSort()
 {
     if (this.SortSettings.IsNullOrEmpty())
     {
         return(LibraryOwner.GetCurrent().Searcher.GetDefaultSort());
     }
     return(this.SortSettings.Select(x => x.Clone()));
 }
 public bool SetSort(IEnumerable <SortSetting> source, bool replaceDefaultSort)
 {
     if (this.GetSort().SequenceEqual(source, (x, y) => x.Equals(y)))
     {
         if (this.SortSettings.IsNullOrEmpty())
         {
             this.SortSettings = source.ToList();
         }
         return(false);
     }
     this.SortSettings = source.ToList();
     if (replaceDefaultSort)
     {
         LibraryOwner.GetCurrent().Searcher.SetDefaultSort(source);
     }
     return(true);
 }
        private async Task <Record[]> SearchAsync
            (FileProperty property, object reference, CompareMode mode)
        {
            var search = new SearchInformation(new ComplexSearch(false));

            search.Root
            .Add(new UnitSearch()
            {
                Property  = property,
                Reference = reference,
                Mode      = mode,
            });

            var library = LibraryOwner.GetCurrent();

            var files = await search.SearchAsync(library, 0, 0);

            return(files);
        }
Exemple #5
0
        //public const string settingsFileName = "appsettings.config";
        //private const int settingVersion = 3;


        //private XmlSettingManager<ApplicationSettings> SettingsXml { get; set; }
        //private ApplicationSettings Settings { get; set; }

        //private string GetOldLibraryDirectory()
        //{
        //    var dir = System.Environment.GetFolderPath
        //        (Environment.SpecialFolder.LocalApplicationData);
        //
        //    var saveDirectory =
        //        Path.Combine(dir, @"Packages\60037Boredbone.MikanViewer_8weh06aq8rfkj\LocalState");
        //
        //    return saveDirectory;
        //}

        public async Task ConvertOldLibraryAsync
            (string saveDirectory, string settingFileName, string oldLibraryDirectory, int settingVersion)
        {
            if (saveDirectory == null || settingFileName == null || oldLibraryDirectory == null)
            {
                return;
            }

            Console.WriteLine($"Loading...");

            var config = new LibraryConfiguration(saveDirectory)
            {
                Concurrency    = 512,
                FileTypeFilter = new HashSet <string>(),
                FileSystem     = new FileSystem(),
            };

            LibraryOwner.SetConfig(config);

            using (var library = LibraryOwner.GetCurrent())
            {
                library.InitSettings();
                await library.LoadAsync();

                //ストレージに保存する設定
                var settingsXml = new XmlSettingManager <ApplicationSettings>
                                      (Path.Combine(saveDirectory, settingFileName));

                var settings = settingsXml
                               .LoadXml(XmlLoadingOptions.IgnoreAllException | XmlLoadingOptions.UseBackup)
                               .Value;


                using (var locking = await library.LockAsync())
                {
                    //var saveDirectory = this.GetOldLibraryDirectory();

                    var converter = new LibraryConverter.Compat.Converter();
                    await converter.Start1(oldLibraryDirectory, settings);

                    var data  = library.GetDataForConvert();
                    var count = 0;

                    await converter.Start2(data.Item1, data.Item2, data.Item3,
                                           x => count = x, x =>
                    {
                        Console.CursorLeft = 0;
                        Console.Write($"Importing {x} / {count}");
                    });


                    Console.WriteLine("");

                    library.SaveSettings();
                }


                try
                {
                    settings.Version = settingVersion;
                    settingsXml.SaveXml(settings);
                }
                catch
                {
                }
            }
        }
Exemple #6
0
 public TagManager(string entry)
 {
     this.Tags    = this.DecodeEntry(entry);
     this.library = LibraryOwner.GetCurrent();
 }
Exemple #7
0
 public TagManager(HashSet <int> collection)
 {
     this.Tags    = collection;
     this.library = LibraryOwner.GetCurrent();
 }
Exemple #8
0
        public bool Initialize(string saveDirectory)
        {
            // Set the user interface to display in the same culture as that set in Control Panel.
            System.Threading.Thread.CurrentThread.CurrentUICulture =
                System.Threading.Thread.CurrentThread.CurrentCulture;

            //ストレージに保存する設定
            this.SettingsXml = new XmlSettingManager <ApplicationSettings>
                                   (Path.Combine(saveDirectory, settingsFileName));

            this.Settings = SettingsXml
                            .LoadXml(XmlLoadingOptions.IgnoreAllException | XmlLoadingOptions.UseBackup)
                            .Value;

            this.ImageBuffer = new ImageBuffer().AddTo(this.Disposables);
            this.ImageBuffer.MetaImageExtention = this.MetaImageExtention;

            var config = new LibraryConfiguration(saveDirectory)
            {
                Concurrency    = 512,
                FileTypeFilter = new HashSet <string>(this.FileTypeFilter),
                FileSystem     = new FileSystem(),
            };

            LibraryOwner.SetConfig(config);

            var library = LibraryOwner.GetCurrent();

            library.InitSettings();
            library.LoadAsync().Wait();

            library.AddTo(this.Disposables);

            this.Library = library;


            this.LibraryUpdateHistory = new ReactiveCollection <LibraryUpdateHistoryItem>().AddTo(this.Disposables);

            this.Library.Loaded
            .Subscribe(x => this.LibraryUpdateHistory.AddRangeOnScheduler(
                           x.AddedFiles.Select(y => new LibraryUpdateHistoryItem()
            {
                Date = x.DateTime, Path = y.Key, Type = LibraryUpdateType.Add
            })
                           .Concat(x.RemovedFiles.Select(y => new LibraryUpdateHistoryItem()
            {
                Date = x.DateTime, Path = y.Key, Type = LibraryUpdateType.Remove
            }))
                           .Concat(x.UpdatedFiles.Select(y => new LibraryUpdateHistoryItem()
            {
                Date = x.DateTime, Path = y.Key, Type = LibraryUpdateType.Update
            }))))
            .AddTo(this.Disposables);

            this.SystemNotification = this.Library.Loaded
                                      .Select(x => this.ShowLibraryResult(x))
                                      .Where(x => x != null)
                                      .Publish().RefCount();

            //リソースから文字列を取得
            this.InitializeResourceString();

            //色テーマ
            this.ObserveProperty(x => x.IsDarkTheme)
            .Subscribe(x =>
            {
                ((App)Application.Current).ChangeTheme(x ? darkThemeName : lightThemeName);
            })
            .AddTo(this.Disposables);

            this.ObserveProperty(x => x.BackgroundColor)
            .Subscribe(x =>
            {
                Application.Current.Resources["BasicBackColor"] = new SolidColorBrush(x);
            })
            .AddTo(this.Disposables);

            this.isChanged = true;
            this.PropertyChangedAsObservable().Subscribe(x => this.isChanged = true).AddTo(this.Disposables);


            var libraryHasItem = this.Library.HasItems();

            //ライブラリ更新
            if (libraryHasItem && this.RefreshLibraryOnLaunched)
            {
                this.Library.StartRefreshLibrary(false);
            }

            return(libraryHasItem);
        }
        private async Task <Library> CreateLibraryAsync()
        {
            LibraryOwner.Reset();
            //this.settings?.Folders?.Clear();
            this.FileEnumerator?.Clear();

            var path   = System.IO.Directory.GetCurrentDirectory();
            var config = new LibraryConfigurationDummy(path);

            this.FileEnumerator = new Dictionary <string, FolderContainerDummy>();// = new FolderAccesserDummy();
            //config.FolderAccesser = this.FileEnumerator;

            config.GetChildFoldersFunction = s =>
            {
                var key = s.TrimEnd(System.IO.Path.DirectorySeparatorChar);

                if (!this.FileEnumerator.ContainsKey(key))
                {
                    Debug.WriteLine(key);
                    this.FileEnumerator.ForEach(x => Debug.WriteLine(x.Key + "," + x.Value.Path));
                    return(null);
                }
                return(this.FileEnumerator[key]
                       .Folders?.Select(x => x.Value.Path) ?? new string[0]);
            };

            config.GetFolderFunction = s =>
            {
                var key = s.TrimEnd(System.IO.Path.DirectorySeparatorChar);
                FolderContainerDummy f;
                this.FileEnumerator.TryGetValue(key, out f);
                return(f);
            };

            this.config = config;
            LibraryOwner.SetConfig(config);

            //config.Folders.Add(folder);
            //config.FileExistingChecker = _ => false;

            var library = LibraryOwner.GetCurrent();

            this.settings = new LibrarySettings()
            {
                Version = 10,
            };


            library.InitializeLibrarySettings(settings);

            await library.LoadAsync();


            await library.ClearAsync();

            data.ForEach((x, c) =>
            {
                var f = LoadTestData(x);
                this.AddFolder(f);
                library.Folders.Add(new FolderInformation(f.Path));
            });

            await library.RefreshLibraryAsync(true);

            var search = new SearchInformation(new ComplexSearch(false));

            library.Searcher.AddSearchToDictionary(search);

            return(library);
        }