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
 public void SimpleCommonRoot()
 {
     PathOperations.FindCommonRoot(new[]
     {
         Path.Combine("a", "1.txt"),
         Path.Combine("a", "2.txt")
     })
     .Should().Be("a" + Path.DirectorySeparatorChar);
 }
Example #3
0
        public void ShouldCountSimplePathsGivenSourceAndDestinationNode(string igraph, char isourceNode, char idestinationNode, int expectedNofPaths)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new PathOperations <Char>();

            //Assert
            var actual = sut.FindAllSimplePaths(graph, isourceNode, idestinationNode);

            //Act
            Assert.AreEqual(expectedNofPaths, actual.Count);
        }
Example #4
0
        public void ShouldCountPathsWhenGivenSourceDestinationAndNumberOfStops(string igraph, char isourceNode, char idestinationNode, int inoOfStops, int expectedNoOfPaths)
        {
            //Arrange
            var graph = GraphLoaderHelper.LoadGraphFromString(igraph);
            var sut   = new PathOperations <Char>();

            //Assert
            var actual = sut.CountAllPaths(graph, isourceNode, idestinationNode, inoOfStops);

            //Atc
            Assert.AreEqual(expectedNoOfPaths, actual);
        }
Example #5
0
        internal ProjectNode(string fullPath, Project project) :
            base(project)
        {
            FullPath = Path.GetFullPath(fullPath);
            BaseDir  = Path.GetDirectoryName(FullPath);            // REVIEW: DI?

            _modulesPathList = project
                               .AllModules
                               .Select(module => GetModulePath(BaseDir, module.Path))
                               .ToList();

            string parentPath = (project.Parent != null && !string.IsNullOrEmpty(project.Parent.RelativePath)) ?
                                project.Parent.RelativePath : "../pom.xml";

            _parentPath = PathOperations.Normalize(parentPath);
        }
Example #6
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 #7
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);
        }
Example #8
0
 public void CommonRootWithDifferentSubDirs()
 {
     PathOperations.FindCommonRoot(new[] { @"a\b\1.txt", @"a\c\2.txt" }).Should().Be(@"a\");
     PathOperations.FindCommonRoot(new[] { @"a\b\1.txt", @"a\c\2.txt", @"a\3.txt" }).Should().Be(@"a\");
 }
Example #9
0
 public void SimpleCommonRoot()
 {
     PathOperations.FindCommonRoot(new[] { @"a\1.txt", @"a\2.txt" }).Should().Be(@"a\");
 }
Example #10
0
 public void SingleFile()
 {
     PathOperations.FindCommonRoot(new[] { @"a\b\c\x.y" }).Should().Be(@"a\b\c\");
 }
Example #11
0
 public void EmptySet()
 {
     PathOperations.FindCommonRoot(new string[0]).Should().BeEmpty();
 }
Example #12
0
 public void CommonRootWithDifferentSubDirs()
 {
     PathOperations.FindCommonRoot(new[] { Path.Combine("a", "b", "1.txt"), Path.Combine("a", "c", "2.txt") }).Should().Be("a" + Path.DirectorySeparatorChar);
     PathOperations.FindCommonRoot(new[] { Path.Combine("a", "b", "1.txt"), Path.Combine("a", "c", "2.txt"), Path.Combine("a", "3.txt") }).Should().Be("a" + Path.DirectorySeparatorChar);
 }
Example #13
0
 public void SingleFile()
 {
     PathOperations.FindCommonRoot(new[] { Path.Combine("a", "b", "c", "x.y") })
     .Should().Be(Path.Combine("a", "b", "c") + Path.DirectorySeparatorChar);
 }
Example #14
0
 public FileLoggerFactory(String basePath)
 {
     basePath.VerifyThatStringIsNotNullAndNotEmpty("Parameter 'basePath' is null or empty.");
     this.basePath = PathOperations.CompleteDirectoryPath(basePath);
     DirectoryOperations.EnsureDirectoryExists(this.basePath);
 }