예제 #1
0
        /// <summary>
        /// Apply existing settings to the window
        /// </summary>
        /// <param name="contents">JSON</param>
        private void Setup(dynamic contents)
        {
            m.LoadSettings();
            // Group Names
            cmboGroup.Items.Add("{Any}");
            cmboGroup.SelectedIndex = 0;
            foreach (var chapterID in contents.chapter)
            {
                foreach (var chapter in chapterID)
                {
                    string group = chapter.group_name;
                    if (!IsGroupInList(group))
                    {
                        cmboGroup.Items.Add(group);
                        if (group.Equals(m.settings.group))
                        {
                            cmboGroup.SelectedIndex = cmboGroup.Items.Count - 1;
                        }
                    }
                }
            }

            foreach (string localeOption in cmboLang.Items)
            {
                if (localeOption.StartsWith(m.settings.lang))
                {
                    cmboLang.SelectedItem = localeOption;
                    break;
                }
            }

            if (m.settings.name == "" || m.settings.name == null)
            {
                txtName.Text = m.name;
            }
            else
            {
                txtName.Text = m.settings.name;
            }
        }
예제 #2
0
        /// <summary>
        /// Adds a manga to the database, doubles as a full check of all the files
        /// </summary>
        /// <param name="api">API link</param>
        /// <param name="num">Chapter Number</param>
        public void AddManga(string api, string num, bool isUpdate)
        {
            string json;

            if (api != null)
            {
                using (var wc = new System.Net.WebClient())
                {
                    json = wc.DownloadString(api);
                }
            }
            else
            {
                json = File.ReadAllText(homeFolder + "\\" + num + "\\manga.json");
            }

            // Deserialize the JSON file
            dynamic contents       = JsonConvert.DeserializeObject(json);
            string  mangaName      = contents.manga.title;
            string  mangaDirectory = homeFolder + "\\" + num;

            if (!Directory.Exists(mangaDirectory))
            {
                Logger.Log("Creating directory '" + mangaDirectory + "' and related files");
                Directory.CreateDirectory(mangaDirectory);
                File.WriteAllText(mangaDirectory + "\\manga.json", json); // Write the JSON to a file
                File.WriteAllText(mangaDirectory + "\\tracker", "1|1");   // Write initial tracking info to a file
            }
            File.WriteAllText(mangaDirectory + "\\downloading", "");      // Create "Downloading" file

            Manga m = new Manga(mangaName, new DirectoryInfo(mangaDirectory), "1", "1");

            if (!isUpdate)
            {
                DialogResult result = new FrmMangaSettings(m).ShowDialog();
                MessageBox.Show("Downloading data...\nYou may close the Browser as you desire.");
            }
            m.LoadSettings();
            downloadManager.AddMDToQueue(m, contents.chapter, isUpdate);
            RefreshContents();
        }
예제 #3
0
        /// <summary>
        /// Refreshes the UI and its contents
        /// </summary>
        public void RefreshContents()
        {
            Logger.Log("Refreshing");
            lstManga.Items.Clear();
            lstHentai.Items.Clear();
            mangas.Clear();
            DirectoryInfo root = new DirectoryInfo(homeFolder);

            DirectoryInfo[] dirs = root.GetDirectories("*", SearchOption.TopDirectoryOnly);

            foreach (DirectoryInfo dir in dirs)
            {
                // Logger.Log("Refreshing data for directory '" + dir.Name + "'");
                if (dir.Name == "update")
                {
                    continue;
                }
                else if (!dir.Name.StartsWith("h"))
                {
                    var      json        = File.ReadAllText(dir.FullName + "\\manga.json");
                    var      tracker     = File.ReadAllText(dir.FullName + "\\tracker");
                    string[] trackerData = tracker.Split('|');
                    // Deserialize the JSON file
                    dynamic contents  = JsonConvert.DeserializeObject(json);
                    string  mangaName = contents.manga.title;
                    Manga   m         = new Manga(mangaName, dir, trackerData[0], trackerData[1]);
                    m.LoadSettings();
                    if (m.settings.name == "" || m.settings.name == null)
                    {
                        m.SaveSettings(m.settings.lang, m.settings.group, mangaName);
                        m.LoadSettings();
                    }

                    mangas.Add(m);
                    string name = m.settings.name;
                    if (name.Length > 21)
                    {
                        name = name.Substring(0, 21);
                    }
                    else
                    {
                        name = name.PadRight(21);
                    }
                    lstManga.Items.Add(name + "  »  c" + trackerData[0] + ",p" + trackerData[1]);
                }
                else // Hentai
                {
                    string   title       = File.ReadAllText(dir.FullName + "\\title");
                    var      tracker     = File.ReadAllText(dir.FullName + "\\tracker");
                    string[] trackerData = tracker.Split('|');

                    Manga m = new Manga(title, dir, trackerData[0], trackerData[1]);
                    mangas.Add(m);
                    string name = m.name;
                    if (name.Length > 21)
                    {
                        name = name.Substring(0, 21);
                    }
                    else
                    {
                        name = name.PadRight(21);
                    }
                    lstHentai.Items.Add(name + "  »  p" + trackerData[1]);
                }
            }
            if (lstManga.Items.Count > 0)
            {
                lstManga.SelectedIndex = 0;
            }
            if (lstHentai.Items.Count > 0)
            {
                lstHentai.SelectedIndex = 0;
            }
        }