Example #1
0
 private bool FetchProfile(string profile)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(profile))
         {
             return(false);
         }
         var a = profile.Substring(10, profile.Length - 10);
         if (string.IsNullOrWhiteSpace(a))
         {
             return(false);
         }
         var b = Path.Combine("GameProfiles\\", a);
         if (!File.Exists(b))
         {
             return(false);
         }
         if (File.Exists(Path.Combine("UserProfiles\\", a)))
         {
             _profile = JoystickHelper.DeSerializeGameProfile(Path.Combine("UserProfiles\\", a));
         }
         else
         {
             _profile = JoystickHelper.DeSerializeGameProfile(b);
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #2
0
        private static void ExtractUserProfiles(string path)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var file in Directory.GetFiles(Path.Combine(path, "UserProfiles")))
            {
                var zzz = JoystickHelper.DeSerializeGameProfile(file, false);
                if (zzz == null)
                {
                    continue;
                }

                string code = Path.GetFileNameWithoutExtension(zzz.FileName);
                if (executables.ContainsKey(code))
                {
                    continue;
                }

                string codeStr = "{ \"" + code + "\",";
                sb.Append(codeStr);
                sb.Append(new string(' ', Math.Max(1, 32 - code.Length)));
                sb.Append("@\"");
                sb.Append(zzz.GamePath);
                sb.AppendLine("\" },");
            }

            var str = sb.ToString();
        }
Example #3
0
        private async void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            cbGameList.ItemsSource = _library._gameNames;
            if (modList.Children.Count <= 0)
            {
                WebClient wc = new WebClient();

                byte[] modXML =
                    await wc.DownloadDataTaskAsync(
                        "https://github.com/nzgamer41/tpgamemods/releases/latest/download/mods.xml");

                List <ModData> mods = ReadFromXmlFile <List <ModData> >(modXML);
                if (File.Exists("InstalledMods.xml"))
                {
                    installedGUIDs = ReadFromXmlFile <List <string> >(File.ReadAllBytes("InstalledMods.xml"));
                }
                else
                {
                    installedGUIDs = new List <string>();
                }

                foreach (ModData m in mods)
                {
                    if (File.Exists("UserProfiles\\" + m.GameXML))
                    {
                        GameProfile gp  = JoystickHelper.DeSerializeGameProfile("UserProfiles\\" + m.GameXML, true);
                        string      url = "https://github.com/nzgamer41/tpgamemods/raw/master/" + m.GUID + ".zip";
                        ModControl  mc  = new ModControl(m.ModName, gp.GameName, m.Description, url, m.Creator, gp, this);
                        if (installedGUIDs.Contains(m.GUID))
                        {
                            mc.buttonDl.IsEnabled = false;
                        }
                        modList.Children.Add(mc);
                        modControls.Add(mc);
                    }
                }

                if (modList.Children.Count == 0)
                {
                    Application.Current.Windows.OfType <MainWindow>().Single().ShowMessage("You have no games added that have mods available!");
                }
            }
        }
Example #4
0
        private static GameProfile FindGameProfile(string path, string romPath, string gameName)
        {
            string currentFolderName = Path.GetFileNameWithoutExtension(romPath);

            foreach (var exe in executables)
            {
                var root = RootDirectory(exe.Value);
                if (root == currentFolderName)
                {
                    gameName = exe.Key;
                    break;
                }
            }

            if (File.Exists(Path.Combine(path, "GameProfiles", gameName + ".xml")))
            {
                var profile = JoystickHelper.DeSerializeGameProfile(Path.Combine(path, "GameProfiles", gameName + ".xml"), false);
                if (profile != null)
                {
                    return(profile);
                }
            }

            List <GameProfile> profiles = new List <GameProfile>();

            foreach (var file in Directory.GetFiles(Path.Combine(path, "GameProfiles")))
            {
                var profile = JoystickHelper.DeSerializeGameProfile(file, false);
                if (profile == null)
                {
                    continue;
                }

                if (gameName.Equals(profile.GameName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(profile);
                }

                if (CleanupGameName(gameName).Equals(CleanupGameName(profile.GameName), StringComparison.InvariantCultureIgnoreCase))
                {
                    return(profile);
                }

                if (!string.IsNullOrEmpty(profile.ExecutableName))
                {
                    profiles.Add(profile);
                }
            }


            var uniqueExes = executables
                             .GroupBy(x => RelativeDirectory(x.Value))
                             .Where(x => x.Count() == 1)
                             .Select(y => y.FirstOrDefault())
                             .ToDictionary(y => y.Key, y => y.Value);

            foreach (var profile in profiles)
            {
                var profilName = Path.GetFileNameWithoutExtension(profile.FileName);
                if (!uniqueExes.ContainsKey(profilName))
                {
                    continue;
                }

                var root = RelativeDirectory(uniqueExes[profilName]);
                if (File.Exists(Path.Combine(romPath, root)))
                {
                    return(profile);
                }
            }

            return(null);
        }
Example #5
0
        public override System.Diagnostics.ProcessStartInfo Generate(string system, string emulator, string core, string rom, string playersControllers, ScreenResolution resolution)
        {
            string path = AppConfig.GetFullPath("TeknoParrot");
            string exe  = Path.Combine(path, "TeknoParrotUi.exe");

            if (!File.Exists(exe))
            {
                return(null);
            }

            // ExtractUserProfiles("h:\\");

            string gameName = Path.GetFileNameWithoutExtension(rom);

            GameProfile profile = FindGameProfile(path, rom, gameName);

            if (profile == null)
            {
                SimpleLogger.Instance.Error("Unable to find gameprofile for " + rom);
                return(new ProcessStartInfo()
                {
                    FileName = "WARNING", Arguments = "Unable to find game profile.\r\nPlease make sure the game folder is named like the xml file in emulators/teknoparrot/GameProfiles folder or like the <GameName> element in the xml"
                });
            }

            GameProfile userProfile = null;

            var userProfilePath = Path.Combine(Path.Combine(path, "UserProfiles", Path.GetFileName(profile.FileName)));

            if (File.Exists(userProfilePath))
            {
                userProfile = JoystickHelper.DeSerializeGameProfile(userProfilePath, true);
            }
            else
            {
                JoystickHelper.SerializeGameProfile(profile, userProfilePath);
                userProfile = JoystickHelper.DeSerializeGameProfile(userProfilePath, true);
            }

            if (userProfile == null)
            {
                SimpleLogger.Instance.Error("Unable create userprofile for " + rom);
                return(new ProcessStartInfo()
                {
                    FileName = "WARNING", Arguments = "Unable to create userprofile"
                });
            }

            if (userProfile.GamePath == null || !File.Exists(userProfile.GamePath))
            {
                userProfile.GamePath = FindExecutable(rom, Path.GetFileNameWithoutExtension(userProfile.FileName));

                if (userProfile.GamePath == null)
                {
                    userProfile.GamePath = FindBestExecutable(rom, userProfile.ExecutableName);
                }

                if (userProfile.GamePath == null)
                {
                    SimpleLogger.Instance.Error("Unable to find Game executable for " + rom);
                    return(new ProcessStartInfo()
                    {
                        FileName = "WARNING", Arguments = "Unable to find game executable"
                    });
                }
            }

            var windowed = userProfile.ConfigValues.FirstOrDefault(c => c.FieldName == "Windowed");

            if (windowed != null)
            {
                windowed.FieldValue = "0";
            }

            var hideCursor = userProfile.ConfigValues.FirstOrDefault(c => c.FieldName == "HideCursor");

            if (hideCursor != null)
            {
                hideCursor.FieldValue = "1";
            }

            var customResolution = userProfile.ConfigValues.FirstOrDefault(c => c.FieldName == "CustomResolution");
            var resolutionWidth  = userProfile.ConfigValues.FirstOrDefault(c => c.FieldName == "ResolutionWidth");
            var resolutionHeight = userProfile.ConfigValues.FirstOrDefault(c => c.FieldName == "ResolutionHeight");

            if (customResolution != null && resolutionWidth != null && resolutionHeight != null)
            {
                int resX = (resolution == null ? Screen.PrimaryScreen.Bounds.Width : resolution.Width);
                int resY = (resolution == null ? Screen.PrimaryScreen.Bounds.Height : resolution.Height);

                customResolution.FieldValue = "1";
                resolutionWidth.FieldValue  = resX.ToString();
                resolutionHeight.FieldValue = resY.ToString();
            }

            ConfigureControllers(userProfile);

            JoystickHelper.SerializeGameProfile(userProfile, userProfilePath);

            string profileName = Path.GetFileName(userProfile.FileName);

            _exename     = Path.GetFileNameWithoutExtension(userProfile.GamePath);
            _gameProfile = userProfile;

            return(new ProcessStartInfo()
            {
                FileName = exe,
                Verb = userProfile.RequiresAdmin ? "runas" : null,
                WorkingDirectory = path,
                Arguments = "--profile=" + profileName // + " --startMinimized",
            });
        }