Example #1
0
 /// <summary>
 /// Gets the executable launcher path.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="launcherFilename">The launcher filename.</param>
 /// <returns>System.String.</returns>
 private GameSettings GetExecutableSettings(string path, string launcherFilename)
 {
     if (File.Exists(Path.Combine(path, launcherFilename)))
     {
         var text = File.ReadAllText(Path.Combine(path, launcherFilename));
         if (!string.IsNullOrWhiteSpace(path))
         {
             try
             {
                 var settings = JsonConvert.DeserializeObject <LauncherSettings>(text);
                 var exePath  = PathOperations.ResolveRelativePath(path, settings.ExePath).StandardizeDirectorySeparator();
                 if (File.Exists(exePath))
                 {
                     return(new GameSettings()
                     {
                         ExecutableArgs = string.Join(" ", settings.ExeArgs),
                         ExecutablePath = exePath,
                         UserDir = pathResolver.Parse(settings.GameDataPath)
                     });
                 }
             }
             catch
             {
             }
         }
     }
     return(null);
 }
Example #2
0
        /// <summary>
        /// Gets the game settings from json.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="path">The path.</param>
        /// <returns>IGameSettings.</returns>
        public virtual IGameSettings GetGameSettingsFromJson(IGame game, string path)
        {
            var settingsObject = GetGameLauncherSettings(game, path);

            if (settingsObject != null)
            {
                path = settingsObject.BasePath;
                var model = GetModelInstance <IGameSettings>();
                model.LaunchArguments    = string.Join(" ", settingsObject.ExeArgs);
                model.UserDirectory      = pathResolver.Parse(settingsObject.GameDataPath);
                model.ExecutableLocation = PathOperations.ResolveRelativePath(path, settingsObject.ExePath).StandardizeDirectorySeparator();
                model.CustomModDirectory = string.Empty;
                return(model);
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// Gets the game launcher settings.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="path">The path.</param>
        /// <returns>Models.LauncherSettings.</returns>
        private Models.LauncherSettings GetGameLauncherSettings(IGame game, string path)
        {
            string settingsFile;

            if (string.IsNullOrWhiteSpace(game.LauncherSettingsPrefix))
            {
                settingsFile = game.LauncherSettingsFileName;
            }
            else
            {
                settingsFile = game.LauncherSettingsPrefix + game.LauncherSettingsFileName;
            }
            var infoPath = PathOperations.ResolveRelativePath(path, settingsFile);
            var info     = reader.Read(infoPath);

            if (info == null)
            {
                // Try to traverse down
                var gamePath = Path.GetDirectoryName(path);
                while (!string.IsNullOrWhiteSpace(gamePath))
                {
                    infoPath = PathOperations.ResolveRelativePath(gamePath, settingsFile);
                    info     = reader.Read(infoPath);
                    if (info != null)
                    {
                        break;
                    }
                    gamePath = Path.GetDirectoryName(gamePath);
                }
                path = gamePath;
            }
            if (info != null && info.Any())
            {
                var text = string.Join(Environment.NewLine, info.FirstOrDefault().Content);
                try
                {
                    var model          = GetModelInstance <IGameSettings>();
                    var settingsObject = JsonConvert.DeserializeObject <Models.LauncherSettings>(text);
                    settingsObject.BasePath = path;
                    return(settingsObject);
                }
                catch
                {
                }
            }
            return(null);
        }