Esempio n. 1
0
        private async void MainForm_Shown(object sender, EventArgs e)
        {
            this.SetVersion();
            this.currentTitleStatusLabel.Text = string.Empty;

            if (!File.Exists(Files.DbPath))
            {
                var result = MessageBox.Show(
                    Properties.Resources.Disclaimer,
                    "boo",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Warning);

                if (result == DialogResult.Cancel)
                {
                    Environment.Exit(0);
                }

                this.statusProgressbar.Style = ProgressBarStyle.Marquee;
                this.UpdateAction("Downloading database...");
                await Task.Run(() => DatabaseParser.DownloadDatabase(Files.DbPath));

                this.UpdateAction($"Prettifying JSON in \"{Files.DbPath}\"...");
                File.WriteAllText(Files.DbPath, JsonPrettifier.FormatJson(File.ReadAllText(Files.DbPath)));
            }

            if (!File.Exists(Files.SizesPath))
            {
                this.UpdateAction("Downloading sizes data...");
                await Task.Run(() => DatabaseParser.DownloadSizes(Files.SizesPath));
            }

            this.UpdateAction($"Reading data from \"{Files.DbPath}\" and \"{Files.SizesPath}\"...");
            this.allTitles = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);

            if (File.Exists(Files.FilterPath))
            {
                this.titleFilter = TitleFilterStorage.ParseFilterSettings(Files.FilterPath);
            }

            this.titles = new SortableBindingList <Nintendo3DSTitle>(TitleFilter.FilterTitles(this.allTitles, this.titleFilter));

            this.titlesDataGrid.DoubleBuffered(true);
            this.titlesDataGrid.DataSource = this.titles;
            this.SortDataGrid();

            this.UpdateAction(string.Empty);
            this.currentTitleStatusLabel.Text = string.Empty;
            this.titlesCountLabel.Text        = this.titles.Count + " titles";
            this.statusProgressbar.Style      = ProgressBarStyle.Blocks;

            this.generateAllTicketsButton.Enabled = true;
            this.filterButton.Enabled             = true;
            this.generateQrCodeButton.Enabled     = true;
        }
        public static void Main()
        {
            var html = new HtmlDocument();

            html.Load("tmds.htm");

            var titlesFromTmds = html.DocumentNode
                                 .Descendants("table")
                                 .ToArray()[1]
                                 .Descendants("tr")
                                 .Select(title => title.Descendants("td"))
                                 .Select(a => a.ToArray()[0].InnerText)
                                 .Where(a => a.StartsWith("0004"))
                                 .ToArray();

            var titlesFromDatabase = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(Files.SizesPath)))
                                     .Properties()
                                     .Select(a => a.Name)
                                     .ToArray();

            var missingTitles = titlesFromTmds.Except(titlesFromDatabase).ToArray();

            Console.WriteLine(titlesFromTmds.Length);
            Console.WriteLine(titlesFromDatabase.Length);
            Console.WriteLine(missingTitles.Length);

            const string bigJsonInvalid = "sizes_invalid.json";

            ////var titles = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);

            ////var titlesWithKeys = DatabaseParser.ParseFromDatabase(Files.DbPath, Files.SizesPath);
            ////var bigJsonForComparison = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJson)));
            // var titles = // ParseDatabase("community.xml");

            ////// test
            ////var missingTitles = titles.Except(titlesWithKeys).ToList();
            ////Console.WriteLine(missingTitles.Count);
            ////Console.WriteLine(string.Join("\r\n", missingTitles));
            ////Environment.Exit(0);
            ////// test

            ////// test
            ////var sizes = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJson)));
            ////var totalSize = sizes.Properties().Select(a => long.Parse(a.Value.ToString())).Sum();
            ////Console.WriteLine("Total size of all the eShop: " + DatabaseParser.HumanReadableFileSize(totalSize));
            ////Environment.Exit(0);
            ////// test

            var processed = 0;

            foreach (var title in missingTitles)
            {
                Console.Write($"\r{processed++}/{missingTitles.Length} ({(double)processed / missingTitles.Length * 100:F2}%)");

                var sizesJson = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(Files.SizesPath)));

                var sizesJsonInvalid = JObject.FromObject(JsonConvert.DeserializeObject(File.ReadAllText(bigJsonInvalid)));

                if (sizesJson[title] == null && sizesJsonInvalid[title] == null)
                {
                    long size;

                    try
                    {
                        size = CDNUtils.GetTitleSize(title);
                    }
                    catch (WebException ex)
                    {
                        Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");

                        var statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;

                        sizesJsonInvalid[title] = statusCode;

                        File.WriteAllText(bigJsonInvalid, JsonConvert.SerializeObject(sizesJsonInvalid));
                        Console.WriteLine(title + ": " + statusCode);

                        continue;
                    }

                    sizesJson[title] = size;

                    Console.Write("\r" + new string(' ', Console.WindowWidth - 1) + "\r");

                    // File.WriteAllText(Files.SizesPath, JsonConvert.SerializeObject(sizesJson));
                    // File.AppendAllText("titles.txt", title.TitleId + ": " + size + Environment.NewLine);

                    File.WriteAllText(Files.SizesPath, JsonConvert.SerializeObject(sizesJson));
                    Console.WriteLine(title + ": " + DatabaseParser.HumanReadableFileSize(size));
                }
            }

            var json        = File.ReadAllText(Files.SizesPath);
            var invalidJson = File.ReadAllText(bigJsonInvalid);

            File.WriteAllText(Files.SizesPath, JsonPrettifier.FormatJson(json));
            File.WriteAllText(bigJsonInvalid, JsonPrettifier.FormatJson(invalidJson));

            Console.WriteLine("Finished at " + DateTime.Now);
            Console.Beep(300, 2000);
        }
Esempio n. 3
0
        private async void checkUpdatesButton_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Check for updates?", "Update", MessageBoxButtons.YesNo);

            if (result == DialogResult.No)
            {
                return;
            }

            this.statusProgressbar.Style = ProgressBarStyle.Marquee;

            const string tempPath  = Files.DbPath + "_temp";
            const string tempSizes = Files.SizesPath + "_temp";

            this.UpdateAction("Downloading new database...");
            using (var client = new WebClient())
            {
                await Task.Run(() => client.DownloadFile("https://3ds.titlekeys.com/json_enc", tempPath));
            }

            this.UpdateAction("Downloading new sizes...");
            using (var client = new WebClient())
            {
                await Task.Run(() => client.DownloadFile("http://housebreaker.net/sizes.json", tempSizes));
            }

            this.UpdateAction("Done!");

            this.UpdateAction("Parsing...");

            var downloadedTitles = DatabaseParser.ParseFromDatabase(tempPath, tempSizes);

            var newTitles     = downloadedTitles.Except(this.allTitles).ToList();
            var newTitleCount = newTitles.Count;

            var newSizes = false;

            foreach (var title in downloadedTitles)
            {
                if (this.allTitles.Where(a => a.TitleId == title.TitleId).Any(otherTitle => otherTitle.Size != title.Size))
                {
                    newSizes = true;
                }
            }

            this.statusProgressbar.Style = ProgressBarStyle.Blocks;

            if (newTitleCount == 0 && !newSizes)
            {
                File.Delete(tempPath);
                File.Delete(tempSizes);

                this.UpdateAction(string.Empty);
                MessageBox.Show("Database is up to date.", "Good news!");
                return;
            }

            if (newTitles.Except(this.allTitles).Count() > 10)
            {
                newTitles = newTitles.Take(10).ToList();
            }

            var more = newTitleCount != newTitles.Count ? $"\r\n and {newTitleCount - 10} more" : string.Empty;

            var parseResult = MessageBox.Show(
                newTitles.Count > 0
                                        ? $"New titles:\r\n{string.Join("\r\n", newTitles)}{more}. Update?"
                                        : "New title size info found. Update?",
                "New titles found",
                MessageBoxButtons.YesNo);

            if (parseResult == DialogResult.Yes)
            {
                var titles = JsonPrettifier.FormatJson(File.ReadAllText(tempPath));
                File.WriteAllText(Files.DbPath, titles);
                File.WriteAllText(Files.SizesPath, File.ReadAllText(tempSizes));

                File.Delete(tempPath);
                File.Delete(tempSizes);

                this.allTitles = downloadedTitles;
                this.FilterTitlesAndUpdate();

                this.UpdateAction("Database updated successfully!");
            }
        }
Esempio n. 4
0
        public static void WriteFilterSettings(TitleFilter filter, string filterPath)
        {
            var output = JsonPrettifier.FormatJson(JsonConvert.SerializeObject(filter));

            File.WriteAllText(filterPath, output);
        }