Beispiel #1
0
        public Deck Deserialize(FsPath file, FsPath dir)
        {
            State.LastLoadedFile = file;

            Deck deck = Deck.Create();

            deck.File = file;

            int  maxLen = 0x8000000;            // 128 MB
            long length = file.File().Length;

            if (length > maxLen)
            {
                deck.Error = $"File size {length} bytes exceeds maximum of {maxLen} bytes";
                return(deck);
            }

            string serialized;

            try
            {
                serialized = file.ReadAllText();
            }
            catch (IOException ex)
            {
                deck.Error = ex.Message;
                return(deck);
            }

            var format = @"*" + file.Extension();

            var formatter = getFormatter(format, serialized);

            if (formatter == null)
            {
                deck.Error = "Deck format is not supported";
                return(deck);
            }

            deck = LoadSerialized(format, serialized, exact: false);

            deck.File = file;

            if (deck.Name == null)
            {
                string getNestedFileName() =>
                dir.Base().Join(file.RelativeTo(dir)).Value
                .Replace(new string(Path.DirectorySeparatorChar, 1), Environment.NewLine);

                var extension = file.Extension();

                string nameBase = !dir.HasValue()
                                        ? file.Basename()
                                        : getNestedFileName();

                deck.Name = nameBase.Substring(0, nameBase.Length - extension.Length);
            }

            return(deck);
        }
Beispiel #2
0
        private void load(FsPath fileName)
        {
            string serialized;

            try
            {
                serialized = fileName.ReadAllText();
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                MessageBox.Show($"Failed to open `{fileName}`, {ex}");
                return;
            }

            ReportSettings settings;

            try
            {
                settings = JsonConvert.DeserializeObject <ReportSettings>(serialized);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                MessageBox.Show($"Failed to read chart from `{fileName}`, {ex}");
                return;
            }

            _formChart.Title = fileName.Basename(extension: false);
            _formChart.LoadSavedChart(settings);
        }
Beispiel #3
0
        public void RenameWizardsWebpageImages(string htmlFile, string targetSubdir)
        {
            FsPath htmlPath  = HtmlDir.Join(htmlFile);
            FsPath targetDir = DevPaths.GathererOriginalDir.Join(targetSubdir);

            string htmlFileName  = htmlPath.Basename(extension: false);
            FsPath directoryName = htmlPath.Parent();

            if (!directoryName.HasValue())
            {
                throw new ArgumentException(htmlPath.Value, nameof(htmlPath));
            }

            FsPath filesDirectory = directoryName.Join(htmlFileName + "_files");

            string content = htmlPath.ReadAllText();
            var    matches = _imgTagPattern.Matches(content);

            targetDir.CreateDirectory();
            foreach (Match match in matches)
            {
                string originalFileName = match.Groups["file"].Value;
                string ext = Path.GetExtension(originalFileName);

                FsPath filePath = filesDirectory.Join(originalFileName);

                string name = HttpUtility.HtmlDecode(match.Groups["name"].Value)
                              .Replace(" // ", "");

                FsPath defaultTargetPath = targetDir.Join(name + ext);

                bool defaultTargetExists = defaultTargetPath.IsFile();

                if (defaultTargetExists || getTargetPath(1).IsFile())
                {
                    if (defaultTargetExists)
                    {
                        defaultTargetPath.MoveFileTo(getTargetPath(1));
                    }

                    for (int i = 2; i < 12; i++)
                    {
                        FsPath targetPath = getTargetPath(i);
                        if (!targetPath.IsFile())
                        {
                            filePath.CopyFileTo(targetPath, overwrite: false);
                            break;
                        }
                    }
                }
                else
                {
                    filePath.CopyFileTo(defaultTargetPath, overwrite: false);
                }

                FsPath getTargetPath(int num) =>
                targetDir.Join(name + num + ext);
            }
        }
Beispiel #4
0
        public Dictionary <string, Dictionary <string, TcgCard> > GetTcgCardsByTcgSet()
        {
            FsPath cardsFile = _resourcesDir.Join("tcg.json");
            var    json      = cardsFile.ReadAllText();
            var    result    = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, TcgCard> > >(json);

            return(result);
        }
Beispiel #5
0
        public Dictionary <string, Dictionary <string, int> > GetOrderByCard()
        {
            FsPath sortFile = _resourcesDir.Join("tcg.sort.json");

            var json   = sortFile.ReadAllText();
            var result = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, int> > >(json);

            return(result);
        }
Beispiel #6
0
        public List <TcgSet> ParseSets()
        {
            FsPath setListFile = _resourcesDir.Join("tcg.sets.xml");

            var text    = setListFile.ReadAllText();
            var root    = XElement.Parse(text);
            var options = root.Elements("option").ToArray();

            var result = options
                         .Select(option => new TcgSet
            {
                Name = option.Value,
                Code = option.Attribute("value").Value
            })
                         .ToList();

            return(result);
        }