Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        public static Rom GetGameByName(string platformId, string name, out string access)
        {
            access = "";
            try
            {
                string key  = Functions.LoadAPIKEY();
                string json = string.Empty;
                var    url  = Values.BaseAPIURL + "/v1.1/Games/ByGameName?apikey=" + key + "&name=" + name + "&platform=" + platformId;

                using (WebClient client = new WebClient())
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    json            = client.DownloadString(new Uri(url));
                }

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                access = json.Substring(json.IndexOf("remaining_monthly_allowance") + "remaining_monthly_allowance:".Length + 1, 5).Replace(":", "").Replace(",", "").Trim();
                var part = json.Substring(json.IndexOf("games\":") + 7);
                part = part.Substring(0, part.IndexOf("]},\"pages") + 1);
                var list = JsonConvert.DeserializeObject <List <API_Game> >(part);

                List <Rom> games = new List <Rom>();

                foreach (var game in list)
                {
                    if (game.platform.ToString() != platformId)
                    {
                        continue;
                    }
                    games.Add(new Rom()
                    {
                        Id           = game.id.ToString(),
                        DBName       = game.game_title,
                        YearReleased = RomFunctions.GetYear(game.release_date)
                    });

                    return(games[0]);
                }
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
Esempio n. 3
0
        public static bool IsRomPack(Rom rom)
        {
            var ext = RomFunctions.GetFileExtension(rom.FileName).ToLower();

            if (ext == ".gdi" || ext == ".ccd" || ext == ".cue" || ext == ".rom")
            {
                FileInfo file = new FileInfo(rom.FileName);
                if (file.Directory.Name.ToLower() == rom.Name.ToLower())
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public static void SaveRomPictures(Rom rom, string boxPath, string titlePath, string gameplayPath, bool saveAsJpg)
        {
            if (!string.IsNullOrEmpty(boxPath) && File.Exists(boxPath))
            {
                RomFunctions.SavePicture(rom, boxPath, Values.BoxartFolder, saveAsJpg);
            }

            if (!string.IsNullOrEmpty(titlePath) && File.Exists(titlePath))
            {
                RomFunctions.SavePicture(rom, titlePath, Values.TitleFolder, saveAsJpg);
            }

            if (!string.IsNullOrEmpty(gameplayPath) && File.Exists(gameplayPath))
            {
                RomFunctions.SavePicture(rom, gameplayPath, Values.GameplayFolder, saveAsJpg);
            }
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public static bool AddRomsFiles(Platform platform, string[] files)
        {
            bool addedAny = false;

            foreach (var file in files)
            {
                var rom = RomBusiness.Get(platform.Name, RomFunctions.GetFileName(file));

                if (rom == null)
                {
                    rom      = RomBusiness.NewRom(file, platform);
                    addedAny = true;
                    RomBusiness.SetRom(rom);
                }
            }

            return(addedAny);
        }
Esempio n. 8
0
        public static bool MatchImagesExact(string[] images, string romName, out string imageFoundPath)
        {
            imageFoundPath = string.Empty;
            bool found = false;

            foreach (var image in images)
            {
                string imageTrimmed = RomFunctions.TrimRomName(image);

                if (imageTrimmed == romName)
                {
                    found          = true;
                    imageFoundPath = image;
                    break;
                }
            }

            return(found);
        }
Esempio n. 9
0
        private static bool RenameRomFileStandard(Rom rom, string changeFileName, bool changeZipFileName)
        {
            string oldFile = rom.Platform.DefaultRomPath + "\\" + rom.FileName;
            string newFile = rom.Platform.DefaultRomPath + "\\" + changeFileName;

            if (File.Exists(newFile))
            {
                throw new Exception("A file named \"" + newFile + "\" already exists!");
            }

            File.Move(oldFile, newFile);
            rom.FileName = changeFileName;

            if (changeZipFileName && RomFunctions.GetFileExtension(newFile) == ".zip")
            {
                RomFunctions.ChangeRomNameInsideZip(newFile);
            }

            return(true);
        }
        public static string DiscoverGameId(Rom rom)
        {
            if (rom.Platform == null)
            {
                return(string.Empty);
            }

            if (string.IsNullOrEmpty(rom.Platform.Id))
            {
                return(string.Empty);
            }

            var file = Values.JsonFolder + "\\" + rom.Platform.Name + ".json";
            var json = string.Empty;

            if (File.Exists(file))
            {
                json = File.ReadAllText(file);
            }

            var games = APIFunctions.GetGamesListByPlatform(rom.Platform.Id, json, rom.Platform.Name);

            if (games == null)
            {
                return(string.Empty);
            }

            var romName = RomFunctions.TrimRomName(rom.Name);

            foreach (var game in games)
            {
                var gameName = RomFunctions.TrimRomName(game.DBName);

                if (gameName == romName)
                {
                    return(game.Id);
                }
            }

            return(string.Empty);
        }
        public static void OpenApplicationByCMDWriteLineCD(Rom rom)
        {
            if (rom.Platform.Emulators == null || rom.Platform.Emulators.Count == 0)
            {
                return;
            }

            var emu = rom.Platform.Emulators[0];

            if (!string.IsNullOrEmpty(rom.Platform.DefaultEmulator))
            {
                var defaultEmu = rom.Platform.Emulators.FirstOrDefault(x => x.Name == rom.Platform.DefaultEmulator);

                if (defaultEmu != null)
                {
                    emu = defaultEmu;
                }
            }

            ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe");
            Process          p         = new Process();

            startInfo.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardInput  = true;
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            p = Process.Start(startInfo);

            string changeDir = "cd " + RomFunctions.GetRomDirectory(emu.Path);
            string exe       = emu.Path.Remove(0, emu.Path.LastIndexOf("\\") + 1);
            string path      = emu.Command.Replace("%EMUPATH%", "\"" + exe + "\"")
                               .Replace("%ROMPATH%", "\"" + rom.Platform.DefaultRomPath + "\\" + rom.FileName + "\"")
                               .Replace("%ROMNAME%", rom.FileNameNoExt)
                               .Replace("%ROMFILE%", rom.FileName);

            p.StandardInput.WriteLine(changeDir);
            p.StandardInput.WriteLine(path);
            p.StandardInput.WriteLine("exit");
        }
Esempio n. 12
0
        public static void SavePictureFromUrl(Rom rom, string url, string pictureType, bool saveAsJpg)
        {
            if (url == "")
            {
                return;
            }
            string extension = url.Substring(url.LastIndexOf("."));
            string imagePath = "image" + extension;

            if (url.ToLower().Contains("https:"))
            {
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
            }

            using (WebClient client = new WebClient())
            {
                client.DownloadFile(new Uri(url), imagePath);
            }

            RomFunctions.SavePicture(rom, imagePath, pictureType, saveAsJpg);
            File.Delete(imagePath);
        }
Esempio n. 13
0
        public static List <Rom> GetGamesListByPlatform(string platformId, string json, string platformName)
        {
            try
            {
                if (string.IsNullOrEmpty(json))
                {
                    json = GetGamesListJSONByPlatform(platformId, platformName);
                }

                if (json == null)
                {
                    throw new APIException("Cound not get json");
                }

                var        jobject = (JArray)JsonConvert.DeserializeObject(json);
                List <Rom> games   = new List <Rom>();

                foreach (var game in jobject)
                {
                    var objGame = (JObject)game;
                    games.Add(new Rom()
                    {
                        Id           = objGame.SelectToken("id").ToString(),
                        DBName       = objGame.SelectToken("game_title").ToString(),
                        YearReleased = RomFunctions.GetYear(objGame.SelectToken("release_date").ToString())
                    });
                }

                return(games.OrderBy(x => x.Name).ToList());
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public static bool MatchImages(string[] images, Dictionary <string, Classes.Region> imageRegion, string romName, out string imageFoundPath)
        {
            imageFoundPath = string.Empty;
            bool   found      = false;
            string romTrimmed = RomFunctions.TrimRomName(romName);
            var    romRegion  = RomFunctions.DetectRegion(romName);

            foreach (var image in images)
            {
                string imageTrimmed = RomFunctions.TrimRomName(image);

                if (imageTrimmed == romTrimmed && imageRegion[RomFunctions.GetFileName(image)] == romRegion)
                {
                    found          = true;
                    imageFoundPath = image;
                    break;
                }
            }

            if (!found)
            {
                foreach (var image in images)
                {
                    string imageTrimmed = RomFunctions.TrimRomName(image);

                    if (imageTrimmed == romTrimmed)
                    {
                        found          = true;
                        imageFoundPath = image;
                        break;
                    }
                }
            }

            return(found);
        }
Esempio n. 17
0
        public static Rom GetGameDetails(string gameId, Platform platform, out string access)
        {
            access = "";
            try
            {
                var publishers = GetPublishers();
                var developers = GetDevelopers();

                string key  = Functions.LoadAPIKEY();
                string json = string.Empty;
                var    url  = Values.BaseAPIURL + "/v1/Games/ByGameID?apikey=" + key + "&id=" + gameId;

                using (WebClient client = new WebClient())
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    try
                    {
                        json = client.DownloadString(new Uri(url));

                        if (string.IsNullOrEmpty(json))
                        {
                            throw new Exception();
                        }
                    }
                    catch
                    {
                        if (platform != null)
                        {
                            var pjson = RomFunctions.GetPlatformJson(platform.Name);
                            var list  = GetGamesListByPlatform(platform.Id, pjson, platform.Name);

                            return(list.FirstOrDefault(x => x.Id == gameId));
                        }
                    }
                }

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                var result = new Rom();
                access = json.Substring(json.IndexOf("remaining_monthly_allowance") + "remaining_monthly_allowance:".Length + 1, 5).Replace(":", "").Replace(",", "").Trim();
                var jobject = (JObject)JsonConvert.DeserializeObject(json);
                var jgame   = jobject.SelectToken("data.games").First();
                result.Id           = gameId;
                result.DBName       = jgame.SelectToken("game_title").ToString();
                result.YearReleased = RomFunctions.GetYear(jgame.SelectToken("release_date").ToString());
                //result.Description = jobject.SelectToken("data.games").First().SelectToken("description").ToString();

                result.Platform = new Platform();

                try
                {
                    var jplatform = jgame.SelectToken("platform");

                    if (jplatform != null)
                    {
                        result.Platform.Id = jplatform.ToString();
                        var list = Functions.GetPlatformsXML();
                        result.Platform.Name = list[result.Platform.Id];
                    }
                }
                catch
                {
                }

                try
                {
                    var jpublisher = jgame.SelectToken("publisher");

                    if (jpublisher != null)
                    {
                        result.Publisher = publishers[Convert.ToInt32(jpublisher.ToString())];
                    }
                }
                catch
                {
                }

                try
                {
                    var jdevelopers = jgame.SelectToken("developers");

                    if (jdevelopers != null)
                    {
                        result.Developer = developers[Convert.ToInt32(jdevelopers.First().ToString())];
                    }
                }
                catch
                {
                }

                return(result);
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
Esempio n. 18
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);
        }