Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Save changes to Manga Details
            if (GlobalVar.ShowYesNo("Are you sure you want to overwrite Manga details?"))
            {
                string PATH = txtMangaPath.Text;
                string file = PATH + @"\details.json";
                // Check if previous file exists, and delete it
                if (File.Exists(file))
                {
                    File.Delete(file);
                }
                // Setup MangaInfo.cs first
                MangaInfo manga = new MangaInfo();
                manga.title       = txtTitle.Text;
                manga.artist      = txtArtist.Text;
                manga.author      = txtAuthor.Text;
                manga.description = txtSummary.Text.Replace("\r", "");
                // Process Genre
                string Genre = "";
                foreach (string s in txtGenre.Text.Replace("\r\n", ",").Split(','))
                {
                    if (String.IsNullOrWhiteSpace(s) == false)
                    {
                        Genre += s.Trim() + ", ";
                    }
                }
                Genre = Genre.Trim();
                Genre = Genre.TrimEnd(',');
                List <string> genreDone = new List <string>();
                genreDone.Add(Genre);
                manga.genre = genreDone.ToArray();
                // Process Status
                int index = Array.IndexOf(cbItemStatus, cbStatus.Text);
                if (index < 1)
                {
                    index = 0;
                }
                manga.status = index.ToString();
                // Serialize into JSON file
                string json = JsonConvert.SerializeObject(manga, Formatting.Indented);

                // Trim json string
                string strRep = "";
                try
                {
                    // Get substring between [ ]
                    string cStart = "[";
                    string cEnd   = "]";
                    var    start  = json.IndexOf(cStart) + cStart.Length;

                    strRep = json.Substring(start, json.IndexOf(cEnd) - start);

                    json = json.Replace(strRep, strRep.Trim());
                }
                catch (Exception ex1)
                {
                    // LogError
                    GlobalVar.LogError(ex1);
                }

                // Write to file
                GlobalVar.WriteToFile(file, json, "Done saving!", "Error on saving Manga details!");

                // Reflect changes to listview item
                foreach (ListViewItem lv in lvManga.Items)
                {
                    // Search all and find
                    if (lv.Tag.ToString() == PATH)
                    {
                        // Found the one
                        lv.Text             = manga.title;
                        lv.SubItems[1].Text = manga.author;                               // author
                        lv.SubItems[2].Text = manga.artist;                               // artist
                        lv.SubItems[3].Text = manga.description;                          // summary
                        lv.SubItems[4].Text = Genre;                                      // genre
                        lv.SubItems[5].Text = MangaStatus(Convert.ToInt32(manga.status)); // status
                        lv.ToolTipText      = StringLVTooltip(GlobalVar.StringLimit(manga.description, SummaryLIMIT), Genre, StringLatestChapters(PATH, ChapterLIMIT));
                        lvManga.Refresh();
                        break;
                    }
                }
            }
        }
Exemple #2
0
        // ############################################################################## BACKGROUND WORKERS
        #region Background Workers
        private void bgw_CMFstart(object sender, DoWorkEventArgs e)
        {
            GlobalVar.ShowLoading(this);

            // Invoke required
            this.Invoke(new Action(() =>
            {
                // Dispose previous images
                ResetCoverList();
                ImgListAdd(DEF_IMGKEY, Image.FromFile(GlobalVar.FILE_DEF_COVER));

                // Set default Picture
                SetPicboxImg();
            }));

            // Read Paths from mangaPaths.txt file in Data folder
            GlobalVar.pathMangaFolder = GlobalVar.ReadAllFromFile(GlobalVar.FILE_MANGAPATH);
            GlobalVar.Log($"Manga Path: {GlobalVar.pathMangaFolder}");

            // Read Paths from mangaTachiyomi.txt file in Data folder
            GlobalVar.pathTachiFolder = GlobalVar.ReadAllFromFile(GlobalVar.FILE_MANGATACHI);
            GlobalVar.Log($"Tachiyomi Path: {GlobalVar.pathTachiFolder}");

            // Get all Folder Names from specified Path
            string[] sDir = (!String.IsNullOrWhiteSpace(GlobalVar.pathMangaFolder)) ? GlobalVar.pathMangaFolder.Split('*') : null;

            // Vars and Objects
            List <string> list     = new List <string>();
            string        imgKey   = "";
            int           count    = 0; // Total Manga counts
            int           countImg = 0; // Image Added to ImageList, used in ListView

            // Clear ListView
            this.Invoke(new Action(() => lvManga.Items.Clear())); // Clear previous items

            // Get all Manga from MangaFolder Path, and Tachiyomi folder
            try
            {
                GlobalVar.Log($"List of Directories to Add:");

                // Loop thru all folders in Manga Folder
                if (sDir != null)
                {
                    foreach (string mainDir in sDir)
                    {
                        foreach (string folder in Directory.GetDirectories(mainDir))
                        {
                            if (String.IsNullOrWhiteSpace(Path.GetFileName(folder)) == false)
                            {
                                // Add to list
                                list.Add(folder);
                                GlobalVar.Log($"Added: {folder}");
                            }
                        }
                    }
                }
                else
                {
                    GlobalVar.Log($"Empty Manga folders!");
                }

                // Loop thru Tachiyomi folder structure
                if (!String.IsNullOrWhiteSpace(GlobalVar.pathTachiFolder))
                {
                    foreach (string src in Directory.GetDirectories(GlobalVar.pathTachiFolder + @"\downloads"))
                    {
                        // Loop thru folder inside sources
                        foreach (string manga in Directory.GetDirectories(src))
                        {
                            // Add to list
                            list.Add(manga);
                        }
                    }
                }

                // Loop thru the list and add to ListView
                if (list.Count > 0)
                {
                    foreach (string mangaPath in list)
                    {
                        // Add to ListView
                        // Create Vars to hold strings
                        string   j1 = "";                  // Manga Title
                        string   j2 = "Unknown";           // Author
                        string   j3 = "Unknown";           // Artist
                        string   j4 = "Manga Summary";     // Description / Summary
                        string[] j5 = new string[] { "" }; // Genre, List
                        string   j6 = "Unknown";           // Status
                        GlobalVar.Log($"Added to ListView: [{ mangaPath }]");

                        // Add Image to ImageList
                        try
                        {
                            string imageFile = mangaPath + @"\cover.jpg";
                            if (File.Exists(imageFile))
                            {
                                countImg += 1;
                                var img = Image.FromFile(imageFile);
                                imgKey = "img" + GlobalVar.ValidateZero(countImg);
                                this.Invoke(new Action(() => ImgListAdd(imgKey, img)));
                                GlobalVar.Log($"Added Image to ImageList. ImagePath ({ imgKey }): { mangaPath }\\cover.jpg");
                            }
                            else
                            {
                                imgKey = DEF_IMGKEY;
                                GlobalVar.Log($"File: 'cover.jpg' does not exists!");
                            }
                        }
                        catch (Exception ex)
                        {
                            // Write to Error Log
                            imgKey = DEF_IMGKEY;
                            GlobalVar.LogError(ex);
                            GlobalVar.Log($"Cannot load image for this item!");
                        }

                        // Deserialize JSON file
                        string deetsfile = GlobalVar.ReadAllFromFile(mangaPath + @"\details.json");
                        if (String.IsNullOrWhiteSpace(deetsfile) == false)
                        {
                            MangaInfo minfo = JsonConvert.DeserializeObject <MangaInfo>(deetsfile);

                            j1 = minfo.title;
                            j2 = minfo.author;
                            j3 = minfo.artist;
                            j4 = minfo.description;
                            j5 = minfo.genre;
                            j6 = minfo.status;
                        }
                        else
                        {
                            j1 = Path.GetFileName(mangaPath);
                            j6 = "0";
                        }

                        // loop thru j5, all genres
                        string j5line = j5[0].ToString();

                        // Create ListView Item
                        ListViewItem temp = new ListViewItem();

                        temp.Text = j1;
                        temp.SubItems.Add(j2);
                        temp.SubItems.Add(j3);
                        temp.SubItems.Add(j4);
                        temp.SubItems.Add(j5line);
                        temp.SubItems.Add(MangaStatus(Convert.ToInt16(j6)));
                        temp.Tag             = mangaPath; // Put the manga path to item tag
                        temp.SubItems[1].Tag = imgKey;    // Put imagekey to subitem tag

                        // Set Image by using ImageKey
                        if (String.IsNullOrWhiteSpace(imgKey))
                        {
                            temp.ImageIndex = 0;
                            GlobalVar.Log($"ListView Item ImageIndex: 0");
                        }
                        else
                        {
                            temp.ImageKey = imgKey;
                            GlobalVar.Log($"ListView Item ImageKey used: { imgKey }");
                        }

                        // Get last 3 Chapters
                        string lastChap = StringLatestChapters(mangaPath, ChapterLIMIT);

                        // Limit Summary to MaxLength characters
                        j4 = GlobalVar.StringLimit(j4, SummaryLIMIT);

                        // Set ToolTip on Item, Mouse Hover
                        temp.ToolTipText = StringLVTooltip(j4, j5line, lastChap);

                        // Add ListView item to ListView
                        this.Invoke(new Action(() => lvManga.Items.Add(temp)));
                        count += 1;
                    }
                }

                e.Result = count;
            }
            catch (Exception excpt)
            {
                // Log error
                GlobalVar.LogError(excpt);
                e.Result = null;
            }
        }