Ejemplo n.º 1
0
        public static void RenameRomPictures(Rom rom, string newFileName)
        {
            var newname = RomFunctions.GetFileNameNoExtension(newFileName);

            if (newname != rom.FileNameNoExt)
            {
                string boxpic      = RomFunctions.GetRomPicture(rom, Values.BoxartFolder);
                string titlepic    = RomFunctions.GetRomPicture(rom, Values.TitleFolder);
                string gameplaypic = RomFunctions.GetRomPicture(rom, Values.GameplayFolder);

                if (!string.IsNullOrEmpty(boxpic))
                {
                    File.Move(boxpic, boxpic.Substring(0, boxpic.LastIndexOf("\\")) + "\\" + newname + boxpic.Substring(boxpic.LastIndexOf(".")));
                }

                if (!string.IsNullOrEmpty(titlepic))
                {
                    File.Move(titlepic, titlepic.Substring(0, titlepic.LastIndexOf("\\")) + "\\" + newname + titlepic.Substring(titlepic.LastIndexOf(".")));
                }

                if (!string.IsNullOrEmpty(gameplaypic))
                {
                    File.Move(gameplaypic, gameplaypic.Substring(0, gameplaypic.LastIndexOf("\\")) + "\\" + newname + gameplaypic.Substring(gameplaypic.LastIndexOf(".")));
                }
            }
        }
Ejemplo n.º 2
0
        public static void Fill()
        {
            RomList = new List <Rom>();
            var platformnames = Directory.GetDirectories(Values.PlatformsPath);

            if (!Directory.Exists(Values.PlatformsPath))
            {
                Directory.CreateDirectory(Values.PlatformsPath);
            }

            foreach (var platformname in platformnames)
            {
                var name = platformname.Replace(Values.PlatformsPath + "\\", "");

                var romNodes = XML.GetRomNodes(name);

                if (romNodes == null)
                {
                    continue;
                }

                foreach (XmlNode node in romNodes)
                {
                    Rom rom = new Rom();
                    rom.FileName      = Functions.GetXmlAttribute(node, "FileName");
                    rom.FileNameNoExt = RomFunctions.GetFileNameNoExtension(rom.FileName);
                    rom.Id            = Functions.GetXmlAttribute(node, "Id");
                    rom.Name          = Functions.GetXmlAttribute(node, "Name");
                    rom.DBName        = Functions.GetXmlAttribute(node, "DBName");
                    rom.Platform      = PlatformBusiness.Get(Functions.GetXmlAttribute(node, "Platform"));
                    rom.Genre         = GenreBusiness.Get(Functions.GetXmlAttribute(node, "Genre"));
                    rom.Publisher     = Functions.GetXmlAttribute(node, "Publisher");
                    rom.Developer     = Functions.GetXmlAttribute(node, "Developer");
                    rom.YearReleased  = Functions.GetXmlAttribute(node, "YearReleased");
                    rom.Description   = Functions.GetXmlAttribute(node, "Description");
                    var idLocked = Functions.GetXmlAttribute(node, "IdLocked");
                    rom.IdLocked = string.IsNullOrEmpty(idLocked) ? false : Convert.ToBoolean(idLocked);
                    var favorite = Functions.GetXmlAttribute(node, "Favorite");
                    rom.Favorite = string.IsNullOrEmpty(favorite) ? false : Convert.ToBoolean(favorite);
                    rom.Emulator = Functions.GetXmlAttribute(node, "Emulator");
                    rom.Series   = Functions.GetXmlAttribute(node, "Series");
                    float result = 0;

                    if (float.TryParse(Functions.GetXmlAttribute(node, "Rating"), out result))
                    {
                        rom.Rating = result;
                    }

                    rom.Status    = RomStatusBusiness.Get(rom.Platform.Name, rom.FileName);
                    rom.RomLabels = RomLabelsBusiness.Get(rom.Platform.Name, rom.FileName);

                    RomList.Add(rom);
                }
            }
        }
Ejemplo n.º 3
0
        public static List <string> GetPics(string platform, PicType type, bool getFullPath, bool skipExtension)
        {
            List <string> result    = new List <string>();
            string        picfolder = "";

            if (type == PicType.BoxArt)
            {
                picfolder = Values.BoxartFolder;
            }
            else if (type == PicType.Title)
            {
                picfolder = Values.TitleFolder;
            }
            else
            {
                picfolder = Values.GameplayFolder;
            }

            var path = Environment.CurrentDirectory + "\\" + Values.PlatformsPath + "\\" + platform + "\\" + picfolder;

            if (!Directory.Exists(path))
            {
                return(result);
            }

            var list = Directory.GetFiles(path).ToList();

            if (!getFullPath)
            {
                foreach (var item in list)
                {
                    if (skipExtension)
                    {
                        result.Add(RomFunctions.GetFileNameNoExtension(item));
                    }
                    else
                    {
                        result.Add(RomFunctions.GetFileName(item));
                    }
                }
            }
            else
            {
                result = list;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static void CopyDBName(string dbName, bool keepSuffix, string oldRomName, string oldFileName, out string newRomName, out string newFileName)
        {
            newRomName  = "";
            newFileName = "";

            if (string.IsNullOrEmpty(dbName.Trim()))
            {
                return;
            }

            int bracketindex = oldFileName.IndexOf('[');
            int parindex     = oldFileName.IndexOf('(');
            int suffixIndex  = 0;

            if (bracketindex > -1 && parindex == -1)
            {
                suffixIndex = bracketindex;
            }
            else if (bracketindex == -1 && parindex > -1)
            {
                suffixIndex = parindex;
            }
            else if (bracketindex > -1 && parindex > -1)
            {
                suffixIndex = bracketindex > parindex ? parindex : bracketindex;
            }

            string suffix = suffixIndex == 0 ? string.Empty : RomFunctions.GetFileNameNoExtension(oldFileName).Substring(suffixIndex);

            if (keepSuffix)
            {
                newRomName  = dbName + " " + suffix;
                newFileName = dbName.Replace(":", " -") + " " + suffix;
            }
            else
            {
                newRomName  = dbName;
                newFileName = dbName.Replace(":", " -");
            }

            newFileName = newFileName + RomFunctions.GetFileExtension(oldFileName);

            newRomName  = newRomName.Trim();
            newFileName = newFileName.Trim();
        }
Ejemplo n.º 5
0
        public static string FillEmuName(string name, string path, bool userRetroarch, string corename = null)
        {
            if (name == "" && path != "")
            {
                if (path.EndsWith(".exe"))
                {
                    if (File.Exists(path))
                    {
                        FileInfo file = new FileInfo(path);
                        name = file.Name.Replace(".exe", "");

                        if (userRetroarch && name == "retroarch" && !string.IsNullOrEmpty(corename))
                        {
                            name += " (" + RomFunctions.GetFileNameNoExtension(corename).Replace("_libretro", "") + ")";
                            return(name);
                        }
                    }
                }
            }

            return(name);
        }
Ejemplo n.º 6
0
        public static Rom NewRom(string file, Platform platform, bool rompack = false)
        {
            var rom = new Rom();

            rom.FileName      = RomFunctions.GetFileName(file, rompack);
            rom.FileNameNoExt = RomFunctions.GetFileNameNoExtension(file);
            rom.Platform      = platform;

            if (platform != null && platform.Id == "23")//arcade
            {
                rom.Name = RomFunctions.GetMAMENameFromCSV(RomFunctions.GetFileNameNoExtension(file));

                if (rom.Name == "")
                {
                    rom.Name = RomFunctions.GetFileNameNoExtension(file);
                }
            }
            else
            {
                rom.Name = RomFunctions.GetFileNameNoExtension(file);
            }

            return(rom);
        }
Ejemplo n.º 7
0
        public static Rom SetRom(Rom rom, string id, string fileName,
                                 string romName, string series, string genre, string status, List <RomLabel> labels, string publisher,
                                 string developer, string description, string year, string dbName,
                                 string rating, bool idLocked, bool changeZipName,
                                 string boxPath, string titlePath, string gameplayPath, bool saveAsJpg, string emulator)
        {
            rom.Genre = string.IsNullOrEmpty(genre) ? null : GenreBusiness.Get(genre);

            string oldfile = rom.FileName;

            rom.Id           = id;
            rom.Name         = romName;
            rom.Publisher    = publisher;
            rom.Developer    = developer;
            rom.Description  = description;
            rom.YearReleased = year;
            rom.DBName       = dbName;
            rom.Series       = series;
            rom.IdLocked     = idLocked;
            rom.Emulator     = emulator;
            float ratingParse = 0;

            if (float.TryParse(rating, out ratingParse))
            {
                if (ratingParse > 0 && ratingParse <= 10)
                {
                    rom.Rating = ratingParse;
                }
            }

            RomFunctions.RenameRomPictures(rom, fileName);
            RomFunctions.RenameRomFile(rom, fileName, changeZipName);

            if (string.IsNullOrEmpty(rom.Id))
            {
                rom.DBName = string.Empty;
            }

            if (oldfile != rom.FileName)
            {
                Set(rom, oldfile);

                if (rom.Status != null)
                {
                    RomStatusBusiness.DeleteRomStatus(rom.Status);
                    rom.Status = null;
                }

                if (rom.RomLabels != null)
                {
                    RomLabelsBusiness.DeleteRomLabels(rom.Platform.Name, oldfile);
                    rom.RomLabels = null;
                }
            }
            else
            {
                Set(rom);
            }

            RomFunctions.SaveRomPictures(rom, boxPath, titlePath, gameplayPath, saveAsJpg);
            RomLabelsBusiness.SetRomLabel(rom, labels, null);
            RomStatusBusiness.SetRomStatus(rom, status);
            XML.SaveXmlRoms(rom.Platform.Name);
            rom.FileNameNoExt = RomFunctions.GetFileNameNoExtension(romName);
            return(rom);
        }