Пример #1
0
        public ShelfModel ReadJson(string filePath)
        {
            if (Directory.Exists(filePath))
            {
                filePath = Path.Combine(filePath, ".yomuko");
            }
            else if (Path.GetFileName(filePath) != ".yomuko")
            {
                throw new DirectoryNotFoundException("フォルダが存在しない");
            }

            if (!File.Exists(filePath))
            {
                this.Title    = $"本棚[{Path.GetDirectoryName(filePath)}]";
                this.FilePath = filePath;
                this.Initialize();
                this.WriteJson();
                return(this);
            }

            var target = SerializationExtensions.ReadJson(this, filePath);

            target.FilePath = filePath;

            var rootPath = Path.GetDirectoryName(filePath);

            foreach (var b in target.Books)
            {
                b.FilePath = rootPath + "\\" + b.FilePath;
            }

            return(target);
        }