Ejemplo n.º 1
0
        private static void LoadCatalog(string parameters)
        {
            List <EpItem> list     = new List <EpItem>();
            string        itemPath = parameters.ToLower();
            string        dir      = EpItem.GetCatalogPosterDir(itemPath);

            EpItem.CatalogPosterDir = dir;
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            if (File.Exists(itemPath))
            {
                System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(List <EpItem>));
                try
                {
                    using (var sr = new StreamReader(itemPath))
                    {
                        list = serializer.Deserialize(sr) as List <EpItem>;
                    }
                }
                catch { }
            }
            Source         = list;
            CurrentCatalog = itemPath;
        }
Ejemplo n.º 2
0
        private static void CreateUpdateFromPassport(string passportPath)
        {
            List <string> passport = new List <string>(File.ReadAllLines(passportPath));

            if (passport != null)
            {
                EpItem item = EpItem.GetFromPassport(passport, passportPath);
                if (item.GID == null || Guid.Empty.Equals(item.GID))
                {
                    item.GID = Guid.NewGuid();
                }

                string dirname = Path.GetDirectoryName(passportPath);
                if (string.IsNullOrEmpty(item.Name))
                {
                    if (passportPath.Contains(@"/HEN/"))
                    {
                        item.Catalog = "HEN";
                    }
                    else if (passportPath.Contains(@"/MOV/"))
                    {
                        item.Catalog = "MOV";
                    }
                    else if (passportPath.Contains(@"/AMA/"))
                    {
                        item.Catalog = "AMA";
                    }
                    else if (passportPath.Contains(@"/JAV/"))
                    {
                        item.Catalog = "JAV";
                    }
                    else if (passportPath.Contains(@"/WEB/"))
                    {
                        item.Catalog = "WEB";
                    }
                    else if (passportPath.Contains(@"/PTD/"))
                    {
                        item.Catalog = "PTD";
                    }
                    else if (passportPath.Contains(@"/PRS/"))
                    {
                        item.Catalog = "PRS";
                    }
                    else if (passportPath.Contains(@"/COM/"))
                    {
                        item.Catalog = "COM";
                    }


                    item.Name = UppercaseWords(Path.GetFileName(dirname));
                    if (string.IsNullOrEmpty(item.Director) && item.Catalog == "HEN" && item.Kind == "Hentai Artist")
                    {
                        string director = Directory.GetParent(dirname).Name;
                        item.Director = UppercaseWords(director);
                    }
                    else if (string.IsNullOrEmpty(item.Studio) && item.Catalog == "HEN" && item.Kind == "GameCG")
                    {
                        string studio = Directory.GetParent(dirname).Name;
                        item.Studio = studio.ToUpper();
                    }



                    //string sounddir = Path.Combine(dirname, "SOUND");
                    //if (Directory.Exists(sounddir))
                    //{
                    //    var filesmp3 = Directory.GetFiles(sounddir, "*.mp3").ToList();
                    //    var i = 0;
                    //    foreach (string fn in filesmp3)
                    //    {
                    //        i++;
                    //        string filename = Path.GetFileName(fn);
                    //        if (filename.Length < 45)//string.len"0001.a9da9cd436174c35aa1a0fa0d33636b0.mp3")
                    //        {
                    //            string gid = Guid.NewGuid().ToString();
                    //            string newpath = Path.GetFileNameWithoutExtension(filename);
                    //            newpath = $"{newpath}.{gid}.mp3";
                    //            newpath = Path.Combine(sounddir, newpath);
                    //            File.Move(fn, newpath);
                    //        }
                    //    }
                    //}
                    string eventsdir = Path.Combine(dirname, "EVENTS");
                    if (!Directory.Exists(eventsdir))
                    {
                        Directory.CreateDirectory(eventsdir);
                        var filesjpg = Directory.GetFiles(dirname, "*.jpg").ToList();
                        var i        = 0;
                        foreach (string fn in filesjpg)
                        {
                            i++;
                            string filename = Path.GetFileName(fn);
                            if (filename.Length > 100)
                            {
                                filename = filename.Substring(0, 100) + i.ToString() + ".jpg";
                            }
                            string newpath = Path.Combine(eventsdir, filename);
                            File.Move(fn, newpath);
                        }
                        var filespng = Directory.GetFiles(dirname, "*.png").ToList();
                        i = 0;
                        foreach (string fn in filespng)
                        {
                            i++;
                            string filename = Path.GetFileName(fn);
                            if (filename.Length > 100)
                            {
                                filename = filename.Substring(0, 100) + i.ToString() + ".png";
                            }
                            string newpath = Path.Combine(eventsdir, filename);
                            File.Move(fn, newpath);
                        }
                        List <String> cpslist = new List <string>();
                        cpslist.Add(Path.Combine(eventsdir, "1.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "01.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "001.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "0001.jpg"));
                        cpslist.Add(Path.Combine(eventsdir, "00001.jpg"));
                        foreach (var newcaption in cpslist)
                        {
                            if (File.Exists(newcaption))
                            {
                                File.Copy(newcaption, Path.Combine(dirname, "POSTER.jpg"), false);
                                break;
                            }
                        }
                    }
                }
                else
                {
                }



                item.SourceFolderExist = true;
                // size
                var  filesmp3 = Directory.GetFiles(dirname, "*.m4v").ToList();
                long s        = 0;
                int  d        = 1000000;
                foreach (string fn in filesmp3)
                {
                    try
                    {
                        FileInfo fi = new FileInfo(fn);
                        s += fi.Length;
                    }
                    catch (Exception)
                    {
                        // path too long exception
                        //throw;
                    }
                }
                if (s > 0)
                {
                    item.Size = Convert.ToInt32((s / d));
                }

                //poster
                bool copyPoster        = false;
                bool reversecopyPoster = false;
                var  existingItem      = Source.Where(x => x.GID == item.GID).FirstOrDefault();

                string dirPoster     = EpItem.GetCatalogPosterDir(CurrentCatalog);
                string newPostername = Path.Combine(dirPoster, $"{item.GID}.jpg");

                if (existingItem == null)
                {
                    if (string.IsNullOrEmpty(item.Name))
                    {
                        string   name     = Path.GetFileName(Path.GetDirectoryName(passportPath)).ToLower();
                        TextInfo cultInfo = new CultureInfo("en-US", false).TextInfo;
                        item.Name = cultInfo.ToTitleCase(name);
                    }
                    Source.Add(item);
                    UpdateItem(item);
                    copyPoster = true;
                }
                else
                {
                    if (existingItem.LastEdit < item.LastEdit)
                    {
                        existingItem.UpdateFrom(item);
                        copyPoster = true;
                    }
                    else
                    {
                        existingItem.Size              = item.Size;
                        existingItem.ItemPath          = item.ItemPath;
                        existingItem.SourceFolderExist = item.SourceFolderExist;
                        copyPoster        = !File.Exists(newPostername);
                        reversecopyPoster = !copyPoster;
                    }
                }
                if (copyPoster)
                {
                    bool posterExist = File.Exists(item.PosterPath);
                    if (posterExist)
                    {
                        try
                        {
                            File.Copy(item.PosterPath, newPostername, true);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else if (reversecopyPoster)
                {
                    bool posterExist = File.Exists(newPostername);
                    if (posterExist)
                    {
                        try
                        {
                            if (!File.Exists(item.PosterPath))
                            {
                                File.Copy(newPostername, item.PosterPath, false);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
        }