Exemplo n.º 1
0
        public Repository OpenRepositoryWithRetry(IAbsoluteDirectoryPath path, bool createWhenNotExisting = false,
            Action failAction = null) {
            if (createWhenNotExisting && !path.Exists)
                return new Repository(path, createWhenNotExisting);

            using (var autoResetEvent = new AutoResetEvent(false))
            using (var fileSystemWatcher =
                new FileSystemWatcher(path.ToString(), "*.lock") {
                    EnableRaisingEvents = true
                }) {
                var lockFile = path.GetChildFileWithName(Repository.LockFile);
                var fp = Path.GetFullPath(lockFile.ToString());
                fileSystemWatcher.Deleted +=
                    (o, e) => {
                        if (Path.GetFullPath(e.FullPath) == fp)
                            autoResetEvent.Set();
                    };

                while (true) {
                    using (var timer = UnlockTimer(lockFile, autoResetEvent)) {
                        try {
                            return new Repository(path, createWhenNotExisting);
                        } catch (RepositoryLockException) {
                            if (failAction != null)
                                failAction();
                            timer.Start();
                            autoResetEvent.WaitOne();
                            lock (timer)
                                timer.Stop();
                            autoResetEvent.Reset();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ContentPaths(IAbsoluteDirectoryPath path, IAbsoluteDirectoryPath repositoryPath) {
            Contract.Requires<ArgumentNullException>(path != null);
            Contract.Requires<ArgumentNullException>(repositoryPath != null);

            Path = path;
            RepositoryPath = repositoryPath;
        }
 public ContentEngineContent(Guid networkId, Guid id, bool isInstalled, IAbsoluteDirectoryPath path, Guid gameId) {
     NetworkId = networkId;
     Id = id;
     IsInstalled = isInstalled;
     PathInternal = path;
     GameId = gameId;
 }
 public IEnumerable<string> Enumerate(IAbsoluteDirectoryPath path) {
     Contract.Requires<ArgumentNullException>(path != null);
     return Tools.FileUtil.GetFiles(path, "*.bisign")
         .Select(GetSignatureFromFileName).Where(x => !string.IsNullOrWhiteSpace(x))
         .Select(x => x.ToLower())
         .Distinct();
 }
Exemplo n.º 5
0
        async Task<bool> TryCheckUac(IAbsoluteDirectoryPath mp, IAbsoluteFilePath path) {
            Exception ex;
            try {
                mp.MakeSurePathExists();
                if (path.Exists)
                    File.Delete(path.ToString());
                using (File.CreateText(path.ToString())) {}
                File.Delete(path.ToString());
                return false;
            } catch (UnauthorizedAccessException e) {
                ex = e;
            } catch (Exception e) {
                this.Logger().FormattedWarnException(e);
                return false;
            }

            var report = await UserErrorHandler.HandleUserError(new UserErrorModel("Restart the application elevated?",
                             $"The application failed to write to the path, probably indicating permission issues\nWould you like to restart the application Elevated?\n\n {mp}",
                             RecoveryCommands.YesNoCommands, null, ex)) == RecoveryOptionResultModel.RetryOperation;

            if (!report)
                return false;
            RestartWithUacInclEnvironmentCommandLine();
            return true;
        }
Exemplo n.º 6
0
 public static async Task<PackageManager> Create(Repository repo, IAbsoluteDirectoryPath workDir,
     bool createWhenNotExisting = false,
     string remote = null) {
     var pm = new PackageManager(repo, workDir, createWhenNotExisting, remote);
     await repo.RefreshRemotes().ConfigureAwait(false);
     return pm;
 }
Exemplo n.º 7
0
        public PackageManager(Repository repo, IAbsoluteDirectoryPath workDir, bool createWhenNotExisting = false,
            string remote = null) {
            Contract.Requires<ArgumentNullException>(repo != null);
            Contract.Requires<ArgumentNullException>(workDir != null);
            WorkDir = workDir;
            Repo = repo;
            StatusRepo = new StatusRepo();
            Settings = new PackageManagerSettings();

            Repository.Factory.HandlePathRequirements(WorkDir, Repo);

            if (!WorkDir.Exists) {
                if (!createWhenNotExisting)
                    throw new Exception("Workdir doesnt exist");
                WorkDir.MakeSurePathExists();
            }

            if (!string.IsNullOrWhiteSpace(remote)) {
                var config =
                    Repository.DeserializeJson<RepositoryConfigDto>(
                        FetchString(Tools.Transfer.JoinUri(new Uri(remote), "config.json")));
                if (config.Uuid == Guid.Empty)
                    throw new Exception("Invalid remote, does not contain an UUID");
                Repo.AddRemote(config.Uuid, remote);
                Repo.Save();
            }

            Repository.Log("Opening repository at: {0}. Working directory at: {1}", Repo.RootPath, WorkDir);
            _remote = remote;
        }
 public RealVirtualityLauncher(IMediator mediator, IGameLauncherProcess processManager,
     IPathConfiguration pathConfiguration, IFileWriter writer)
     : base(mediator, processManager) {
     Contract.Requires<ArgumentNullException>(writer != null);
     _writer = writer;
     _parPath = pathConfiguration.LocalDataPath.GetChildDirectoryWithName("games");
 }
Exemplo n.º 9
0
 public static async Task<BundleManager> Create(Repository repo, IAbsoluteDirectoryPath workDir,
     bool createWhenNotExisting = false,
     string remote = null) {
     var packageManager =
         await PackageManager.Create(repo, workDir, createWhenNotExisting, remote).ConfigureAwait(false);
     return new BundleManager(packageManager);
 }
			public VariablePathResolvingStatus TryResolve(IEnumerable<KeyValuePair<string, string>> variables,
				out IAbsoluteDirectoryPath resolvedPath, out IReadOnlyList<string> unresolvedVariables)
			{
				Argument.IsNotNull(nameof(variables), variables);

				string path;

				if (!TryResolve(variables, out path, out unresolvedVariables))
				{
					resolvedPath = null;

					return VariablePathResolvingStatus.UnresolvedVariable;
				}

				if (!path.IsValidAbsoluteDirectoryPath())
				{
					resolvedPath = null;

					return VariablePathResolvingStatus.CannotConvertToAbsolutePath;
				}

				resolvedPath = path.ToAbsoluteDirectoryPath();

				return VariablePathResolvingStatus.Success;
			}
Exemplo n.º 11
0
 static IEnumerable<IAbsoluteDirectoryPath> ExistingMods(IAbsoluteDirectoryPath[] paths, params string[] mods) {
     return paths.Any()
         ? mods.Select(
             x => paths.Select(path => path.GetChildDirectoryWithName(x)).FirstOrDefault(p => p.Exists))
             .Where(x => x != null)
         : Enumerable.Empty<IAbsoluteDirectoryPath>();
 }
Exemplo n.º 12
0
 private static IAbsoluteFilePath GetNetEntryFilePath(IAbsoluteDirectoryPath netEntryPath, string asName) {
     var en = netEntryPath ?? AppContext.BaseDirectory.ToAbsoluteDirectoryPath();
     var dll = en.GetChildFileWithName(asName + ".dll");
     var netEntryFilePath = dll.Exists ? dll : en.GetChildFileWithName(asName + ".exe");
         //_entryAssembly.Location.ToAbsoluteFilePath();
     return netEntryFilePath;
 }
Exemplo n.º 13
0
        async Task CheckoutBundles(IAbsoluteDirectoryPath path, Repository repo, string[] packages) {
            var pm = await BundleManager.Create(repo, path).ConfigureAwait(false);
            ConfirmOperationMode(pm.Repo, 2);

            var scope = BundleScope.All;
            if (!string.IsNullOrWhiteSpace(Scope)) {
                if (!Enum.TryParse(Scope, true, out scope))
                    throw new ConsoleHelpAsException("Invalid scope: " + Scope);
            }

            System.Console.WriteLine("Querying Bundles: {0}. Scope: {1}, IncludeOptional: {2}. Additional: {3}",
                String.Join(", ", packages), scope, IncludeOptional, Additional);

            Package[] packs;
            using (new ConsoleProgress(pm.PackageManager.StatusRepo)) {
                packs = await pm.Checkout(new Bundle("selected") {
                    Dependencies =
                        packages.Select(x => new Dependency(x))
                            .ToDictionary(x => x.Name, x => x.GetConstraints()),
                    Required =
                        Additional == null
                            ? new Dictionary<string, string>()
                            : Additional.Split(',')
                                .Select(x => new Dependency(x))
                                .ToDictionary(x => x.Name, x => x.GetConstraints())
                }, IncludeOptional, scope, UseVersionedPackageFolders).ConfigureAwait(false);
            }

            System.Console.WriteLine("\nSuccesfully checked out {0} packages",
                string.Join(", ", packs.Count()));
        }
Exemplo n.º 14
0
        public string ProcessUserconfig(IAbsoluteDirectoryPath modPath, IAbsoluteDirectoryPath gamePath,
            string exisitingChecksum, bool force = true) {
            Contract.Requires<ArgumentNullException>(modPath != null);
            Contract.Requires<ArgumentNullException>(gamePath != null);

            var backupAndClean = force;

            var path = GetUserconfigPath(modPath);
            if (!File.Exists(path) && !Directory.Exists(path))
                return null;

            this.Logger().Info("Found userconfig to process at " + path);

            var checksum = GetConfigChecksum(path);

            if (checksum != exisitingChecksum)
                backupAndClean = true;

            var uconfig = gamePath.GetChildDirectoryWithName("userconfig");
            var uconfigPath = uconfig.GetChildDirectoryWithName(Mod.GetRepoName(modPath.DirectoryName));

            if (backupAndClean)
                new UserconfigBackupAndClean().ProcessBackupAndCleanInstall(path, gamePath, uconfig, uconfigPath);
            else
                new UserconfigUpdater().ProcessMissingFiles(path, gamePath, uconfig, uconfigPath);

            return checksum;
        }
Exemplo n.º 15
0
 public CreateCommand()
 {
     IsCommand("create", "Create a Zsync Download Control File");
     HasRequiredOption("in|f|folder=", "The folder that you will make a control for", (s) => _folder = s.ToAbsoluteDirectoryPath());
     //HasRequiredOption("out=", "The location of the control file", (s) => _file = s.ToAbsoluteFilePath());
     HasRequiredOption("url=", "The root url of the download", (s) => _url = s);
 }
        const int WM_USER = 0x0400; //http://msdn.microsoft.com/en-us/library/windows/desktop/ms644931(v=vs.85).aspx

        public async Task UpgradeOrInstall(IAbsoluteDirectoryPath destination, Settings settings,
            params IAbsoluteFilePath[] files) {
            var theShell = GetTheShell(destination, files);
            if (theShell.Exists)
                await Uninstall(destination, settings, files).ConfigureAwait(false);
            await Install(destination, settings, files).ConfigureAwait(false);
        }
 void HandleUserconfig(IAbsoluteDirectoryPath dir) {
     var userConfigPath = dir.GetChildDirectoryWithName("userconfig");
     if (!userConfigPath.Exists)
         return;
     System.Console.WriteLine("Found userconfig in {0}, processing", dir);
     HandleUserConfigPath(dir, userConfigPath);
 }
Exemplo n.º 18
0
        public Package Import(Repository repo, IAbsoluteDirectoryPath workDir, IAbsoluteFilePath packageFilePath) {
            var metaData = Package.Load(packageFilePath);
            var package = new Package(workDir, metaData, repo);
            package.Commit(metaData.GetVersionInfo());

            return package;
        }
 public async Task StartSession(Uri url, IAbsoluteDirectoryPath destination,
     CancellationToken cancelToken = new CancellationToken()) {
     if (Consts.PluginBrowserFound != Browser.None) {
         Tools.Generic.OpenUrl(url);
         return;
     }
     await StartSessionImpl(url, destination, cancelToken).ConfigureAwait(false);
 }
        public GameInstalledState(IAbsoluteFilePath executable, IAbsoluteDirectoryPath directory, Version version = null) {
            Contract.Requires<ArgumentNullException>(executable != null);
            Contract.Requires<ArgumentNullException>(directory != null);

            Executable = executable;
            Directory = directory;
            Version = version;
        }
 static void MigrateServerModFolder(IAbsoluteDirectoryPath modFolder, IAbsoluteDirectoryPath modPath) {
     var folderName = modFolder.DirectoryName;
     var destination = modPath.GetChildDirectoryWithName(folderName);
     if (!destination.Exists)
         Tools.FileUtil.Ops.MoveDirectory(modFolder, destination);
     else
         Directory.Delete(modFolder.ToString(), true);
 }
			public override bool CanGetRelativePathFrom(IAbsoluteDirectoryPath pivotDirectory)
			{
				Argument.IsNotNull(nameof(pivotDirectory), pivotDirectory);

				string pathResultUnused, failureReasonUnused;

				return AbsoluteRelativePathHelpers.TryGetRelativePath(pivotDirectory, this, out pathResultUnused, out failureReasonUnused);
			}
Exemplo n.º 23
0
 public HandleKeyParams(IAbsoluteDirectoryPath keyPath, string prefix, bool copyKey,
     IAbsoluteDirectoryPath directory, IAbsoluteFilePath key) {
     KeyPath = keyPath;
     Prefix = prefix;
     CopyKey = copyKey;
     Directory = directory;
     Key = key;
 }
Exemplo n.º 24
0
 void ProcessDirectory(ProcessDirectoryOrFileParams spec, IAbsoluteDirectoryPath directory) {
     if (spec.OnlyWhenMissing) {
         ProcessDirectoryOnlyMissing(spec, directory);
         return;
     }
     var biKeyPair = GetKey(spec, directory);
     _biSigner.SignFolder(directory, biKeyPair.PrivateFile, spec.RepackIfFailed);
 }
Exemplo n.º 25
0
        static string GenerateBatContent(IAbsoluteFilePath target, IAbsoluteDirectoryPath workDir, string pars)
            => String.Format(@"
@echo off
echo Starting: {0}
echo From: {1}
echo With params: {2}
cd /D ""{1}""
""{0}"" {2}", target, workDir, pars);
 static void WriteUserConfigTar(IAbsoluteDirectoryPath userConfigPath, IAbsoluteDirectoryPath storePath) {
     storePath.MakeSurePathExists();
     //using (var tarFile = new TmpFileCreated()) {
     Tools.Compression.PackTar(userConfigPath, storePath.GetChildFileWithName("userconfig.tar"));
     //  tarFile.FilePath
     //Tools.Compression.Gzip.GzipAuto(tarFile.FilePath, storePath.GetChildFileWithName("userconfig.tar.gz"));
     //}
 }
Exemplo n.º 27
0
        bool IsRightVersion(IAbsoluteDirectoryPath rsyncDir, KeyValuePair<string, SixRepoModDto> mod) {
            var versionFile = rsyncDir.GetChildFileWithName(Repository.VersionFileName);
            if (!versionFile.Exists)
                return false;

            var repoInfo = TryReadRepoFile(versionFile);
            return (repoInfo != null) && (repoInfo.Guid == mod.Value.Guid) && (repoInfo.Version == mod.Value.Version);
        }
			public override bool CanGetRelativePathFrom(IAbsoluteDirectoryPath pivotDirectory, out string failureMessage)
			{
				Argument.IsNotNull(nameof(pivotDirectory), pivotDirectory);

				string relativePath;

				return AbsoluteRelativePathHelpers.TryGetRelativePath(pivotDirectory, this, out relativePath, out failureMessage);
			}
			public bool CanGetAbsolutePathFrom(IAbsoluteDirectoryPath path, out string failureMessage)
			{
				Argument.IsNotNull(nameof(path), path);

				string absolutePath;

				return AbsoluteRelativePathHelpers.TryGetAbsolutePathFrom(path, this, out absolutePath, out failureMessage);
			}
Exemplo n.º 30
0
        public static string GetRelativeDirectory(this IAbsoluteDirectoryPath path,
            IAbsoluteDirectoryPath possibleRoot) {
            if (path.Equals(possibleRoot) || !path.CanGetRelativePathFrom(possibleRoot) ||
                !path.IsRootedIn(possibleRoot))
                return path.ToString();

            return path.GetRelativePathFrom(possibleRoot).Join();
        }
Exemplo n.º 31
0
        LocalContent ScanForAddonFolders(IAbsoluteDirectoryPath path)
        {
            var dirs = new[] { "addons", "dta", "common", "dll" };

            if (dirs.Any(x => !path.GetChildDirectoryWithName(x).IsEmptySafe()))
            {
                return(!HasContentAlready(path.DirectoryName)
                    ? new ModLocalContent(path.DirectoryName.ToLower(), _realVirtualityGame.Id,
                                          new BasicInstallInfo())
                    : null);
            }
            return(null);
        }
            //
            //  Absolute/Relative pathString conversion
            //
            IRelativeFilePath IAbsoluteFilePath.GetRelativePathFrom(IAbsoluteDirectoryPath pivotDirectory)
            {
                Debug.Assert(pivotDirectory != null);                 // Enforced by contract
                string pathRelative, failureReason;

                if (!AbsoluteRelativePathHelpers.TryGetRelativePath(pivotDirectory, this, out pathRelative, out failureReason))
                {
                    throw new ArgumentException(failureReason);
                }
                Debug.Assert(pathRelative != null);
                Debug.Assert(pathRelative.Length > 0);
                return(new RelativeFilePath(pathRelative + MiscHelpers.DIR_SEPARATOR_CHAR + FileName));
            }
Exemplo n.º 33
0
 public void CreateZsyncFiles(IAbsoluteDirectoryPath rootDirectory,
                              ZsyncMakeOptions options = ZsyncMakeOptions.Default, params string[] excludes)
 {
     foreach (var file in Directory.EnumerateFiles(rootDirectory.ToString(), "*.*", SearchOption.AllDirectories)
              .Where(
                  x => !x.EndsWith(".zsync", StringComparison.CurrentCultureIgnoreCase))
              .Select(x => x.ToAbsoluteFilePath())
              .Where(x => !excludes.Contains(x.FileName))
              )
     {
         CreateZsyncFile(file, options);
     }
 }
Exemplo n.º 34
0
        public void RunExtractPboWithParameters(IAbsoluteFilePath input, IAbsoluteDirectoryPath output,
                                                params string[] parameters)
        {
            if (!input.Exists)
            {
                throw new IOException("File doesn't exist: " + input);
            }
            var startInfo =
                new ProcessStartInfoBuilder(_extractPboBin,
                                            BuildParameters(input.ToString(), output.ToString(), parameters)).Build();

            ProcessExitResult(_processManager.LaunchAndGrabTool(startInfo));
        }
Exemplo n.º 35
0
        static void TryMoveDir(IAbsoluteDirectoryPath dir, IAbsoluteDirectoryPath newModsPath)
        {
            var newPath = newModsPath.GetChildDirectoryWithName(dir.DirectoryName);

            try {
                if (newPath.Exists)
                {
                    Directory.Delete(newPath.ToString(), true);
                }
            } finally {
                Tools.FileUtil.Ops.MoveDirectory(dir, newPath);
            }
        }
Exemplo n.º 36
0
            //
            //  Absolute/Relative pathString conversion
            //
            IAbsoluteFilePath IRelativeFilePath.GetAbsolutePathFrom(IAbsoluteDirectoryPath path)
            {
                Debug.Assert(path != null);                 // Enforced by contracts!
                string pathAbsolute, failureReason;

                if (!AbsoluteRelativePathHelpers.TryGetAbsolutePathFrom(path, this, out pathAbsolute, out failureReason))
                {
                    throw new ArgumentException(failureReason);
                }
                Debug.Assert(pathAbsolute != null);
                Debug.Assert(pathAbsolute.Length > 0);
                return((pathAbsolute + MiscHelpers.DIR_SEPARATOR_CHAR + FileName).ToAbsoluteFilePath());
            }
Exemplo n.º 37
0
        public static async Task <BundleManager> GetBundleManager(IAbsoluteDirectoryPath synqPath,
                                                                  IAbsoluteDirectoryPath workPath,
                                                                  IEnumerable <KeyValuePair <Guid, Uri[]> > remotes = null)
        {
            var repo = GetRepo(synqPath);

            if (remotes != null)
            {
                await ReplaceRemotes(remotes, repo).ConfigureAwait(false);
            }

            return(await GetCM(synqPath, workPath, repo).ConfigureAwait(false));
        }
Exemplo n.º 38
0
        public static void InstallTaskForceRadio(IAbsoluteFilePath fi, IAbsoluteDirectoryPath path, bool force)
        {
            if (!InstallTs3Plugin(fi, path, force))
            {
                return;
            }
            var di = fi.GetBrotherDirectoryWithName("radio-sounds");

            if (di.Exists)
            {
                InstallTs3PluginFolder(di, path, force);
            }
        }
Exemplo n.º 39
0
        bool IsRightVersion(IAbsoluteDirectoryPath rsyncDir, KeyValuePair <string, SixRepoModDto> mod)
        {
            var versionFile = rsyncDir.GetChildFileWithName(Repository.VersionFileName);

            if (!versionFile.Exists)
            {
                return(false);
            }

            var repoInfo = TryReadRepoFile(versionFile);

            return((repoInfo != null) && (repoInfo.Guid == mod.Value.Guid) && (repoInfo.Version == mod.Value.Version));
        }
Exemplo n.º 40
0
                void CopyDirectoryFiles(IAbsoluteDirectoryPath outputFolder, DirectoryInfo di, bool overwrite = false)
                {
                    outputFolder.MakeSurePathExists();

                    foreach (var file in di.EnumerateFiles())
                    {
                        var dest = outputFolder.GetChildFileWithName(file.Name);
                        if (overwrite || !dest.Exists)
                        {
                            Copy(file.FullName.ToAbsoluteFilePath(), dest);
                        }
                    }
                }
            //
            //  Absolute/Relative pathString conversion
            //
            IRelativeDirectoryPath IAbsoluteDirectoryPath.GetRelativePathFrom(IAbsoluteDirectoryPath pivotDirectory)
            {
                Debug.Assert(pivotDirectory != null);
                string pathRelativeString, failureReason;

                if (!AbsoluteRelativePathHelpers.TryGetRelativePath(pivotDirectory, this, out pathRelativeString, out failureReason))
                {
                    throw new ArgumentException(failureReason);
                }
                Debug.Assert(pathRelativeString != null);
                Debug.Assert(pathRelativeString.Length > 0);
                return(pathRelativeString.ToRelativeDirectoryPath());
            }
Exemplo n.º 42
0
        public void HandlePackageRequirements(IAbsoluteDirectoryPath workPath, Repository repository)
        {
            HandlePathRequirements(workPath, repository);

            if (repository.Config.OperationMode == RepositoryOperationMode.SinglePackage)
            {
                ConfirmSinglePackagePath(workPath, repository);
            }
            else
            {
                ConfirmMultiPackagePath(workPath, repository);
            }
        }
Exemplo n.º 43
0
 bool TryInstallPlugin(IAbsoluteDirectoryPath gamePath, IContentEngineContent mod, string plugin, bool force)
 {
     try {
         return(InstallPlugin(gamePath, mod, plugin, force));
     } catch (PathDoesntExistException e) {
         MainLog.Logger.FormattedWarnException(e, "Path: " + e.Path);
     } catch (Win32Exception e) {
         MainLog.Logger.FormattedWarnException(e);
     } catch (Exception ex) {
         MainLog.Logger.FormattedErrorException(ex);
     }
     return(false);
 }
Exemplo n.º 44
0
 public FolderInfo(IAbsoluteDirectoryPath path, ContentInfo contentInfo)
 {
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));
     }
     if (contentInfo == null)
     {
         throw new ArgumentNullException(nameof(contentInfo));
     }
     Path        = path;
     ContentInfo = contentInfo;
 }
Exemplo n.º 45
0
 async Task DownloadFilesAsync(StatusRepo sr,
                               IDictionary <FileFetchInfo, ITransferStatus> transferStatuses,
                               IAbsoluteDirectoryPath destinationPath, IMirrorSelector scoreMirrorSelector)
 {
     destinationPath.MakeSurePathExists();
     sr.Total = transferStatuses.Count;
     using (var multiMirrorFileDownloader = _createMultiMirrorFileDownloader(scoreMirrorSelector))
         using (var multi = _createQueueDownloader(multiMirrorFileDownloader.Value)) {
             await multi.Value
             .DownloadAsync(CreateFileQueueSpec(transferStatuses, destinationPath), sr.CancelToken)
             .ConfigureAwait(false);
         }
 }
Exemplo n.º 46
0
 public void CreateZip(IAbsoluteDirectoryPath directory, IAbsoluteFilePath outputFile)
 {
     using (var arc = ZipArchive.Create()) {
         foreach (var f in directory.DirectoryInfo.EnumerateFiles("*", SearchOption.AllDirectories))
         {
             arc.AddEntry(f.FullName.Replace(directory.ParentDirectoryPath + @"\", ""), f.FullName);
         }
         arc.SaveTo(outputFile.ToString(),
                    new ZipWriterOptions(CompressionType.Deflate)
         {
             DeflateCompressionLevel = CompressionLevel.BestCompression
         });
     }
 }
Exemplo n.º 47
0
        public void Test_Drive()
        {
            IAbsoluteDirectoryPath absoluteDirectoryPath = @"C:\Dir1".ToAbsoluteDirectoryPath();

            Assert.IsTrue(absoluteDirectoryPath.DriveLetter.ToString() == "C");
            absoluteDirectoryPath = @"c:\Dir1".ToAbsoluteDirectoryPath();
            Assert.IsTrue(absoluteDirectoryPath.DriveLetter.ToString() == "c");

            IAbsoluteFilePath absoluteFilePath = @"C:\Dir1\File.txt".ToAbsoluteFilePath();

            Assert.IsTrue(absoluteFilePath.DriveLetter.ToString() == "C");
            absoluteFilePath = @"c:\Dir1\File.txt".ToAbsoluteFilePath();
            Assert.IsTrue(absoluteFilePath.DriveLetter.ToString() == "c");
        }
Exemplo n.º 48
0
            public IAbsoluteDirectoryPath FindParentWithName(IAbsoluteDirectoryPath path, string key)
            {
                var parent = path;

                while (parent.HasParentDirectory)
                {
                    parent = parent.ParentDirectoryPath;
                    if (parent.DirectoryName.Equals(key, StringComparison.OrdinalIgnoreCase))
                    {
                        return(parent);
                    }
                }
                return(null);
            }
Exemplo n.º 49
0
 void TryUserconfigDirectory(IAbsoluteDirectoryPath path, IAbsoluteDirectoryPath uconfigPath)
 {
     try {
         Tools.FileUtil.Ops.CopyDirectoryWithUpdaterFallbackAndRetry(path, uconfigPath);
     } catch (Win32Exception ex) {
         if (ex.NativeErrorCode != Win32ErrorCodes.ERROR_CANCELLED_ELEVATION)
         {
             throw;
         }
         throw ex.HandleUserCancelled();
     } catch (IOException e) {
         this.Logger().FormattedWarnException(e);
     }
 }
Exemplo n.º 50
0
 public void MoveDirectory(IAbsoluteDirectoryPath sourcePath, IAbsoluteDirectoryPath destinationPath)
 {
     if (IsSameRoot(sourcePath, destinationPath))
     {
         var tmp = destinationPath + GenericTools.TmpExtension;
         Directory.Move(sourcePath.ToString(), tmp);
         Directory.Move(tmp, destinationPath.ToString());
     }
     else
     {
         CopyDirectoryWithRetry(sourcePath, destinationPath, true);
         Directory.Delete(sourcePath.ToString(), true);
     }
 }
Exemplo n.º 51
0
        public ContentPaths(IAbsoluteDirectoryPath path, IAbsoluteDirectoryPath repositoryPath)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (repositoryPath == null)
            {
                throw new ArgumentNullException(nameof(repositoryPath));
            }

            Path           = path;
            RepositoryPath = repositoryPath;
        }
Exemplo n.º 52
0
 void TryUserconfigDirectory(IAbsoluteDirectoryPath path, IAbsoluteDirectoryPath uconfigPath)
 {
     try {
         Tools.FileUtil.Ops.CopyDirectoryWithUpdaterFallbackAndRetry(path, uconfigPath);
     } catch (Win32Exception ex) {
         if (ex.IsElevationCancelled())
         {
             throw ex.HandleUserCancelled();
         }
         throw;
     } catch (IOException e) {
         this.Logger().FormattedWarnException(e);
     }
 }
Exemplo n.º 53
0
        public void Test_GetRelativePathWithError3()
        {
            IAbsoluteDirectoryPath absoluteDirectoryPathTo   = @"C:\Dir1".ToAbsoluteDirectoryPath();
            IAbsoluteDirectoryPath absoluteDirectoryPathFrom = @"D:\Dir1".ToAbsoluteDirectoryPath();

            Assert.IsFalse(absoluteDirectoryPathTo.CanGetRelativePathFrom(absoluteDirectoryPathFrom));
            string failureReason;

            Assert.IsFalse(absoluteDirectoryPathTo.CanGetRelativePathFrom(absoluteDirectoryPathFrom, out failureReason));
            Assert.IsTrue(failureReason == @"Cannot compute relative path from 2 paths that are not on the same volume 
   PathFrom = ""D:\Dir1""
   PathTo   = ""C:\Dir1""");
            Assert.Throws(typeof(ArgumentException), delegate { absoluteDirectoryPathTo.GetRelativePathFrom(absoluteDirectoryPathFrom); });
        }
Exemplo n.º 54
0
        IEnumerable <IAbsolutePath> TryGetModFolders(IAbsoluteDirectoryPath modPath)
        {
            var di = new DirectoryInfo(modPath.ToString());

            if (!di.Exists)
            {
                return(Enumerable.Empty <IAbsolutePath>());
            }

            return(Enumerable.Repeat(di, 1).Concat(di.RecurseFilterDottedDirectories())
                   .Select(x => x.FullName)
                   .Where(modPathValidator.Validate)
                   .Select(x => x.ToAbsoluteDirectoryPath()));
        }
 public SULaunchGameSteamArgumentsBuilder(LaunchGameWithSteamInfo spec, IAbsoluteDirectoryPath steamPath)
     : base(spec)
 {
     if (steamPath == null)
     {
         throw new ArgumentNullException(nameof(steamPath));
     }
     if (!(spec.SteamAppId > 0))
     {
         throw new ArgumentNullException("spec.SteamAppId > 0");
     }
     _steamPath = steamPath;
     _spec      = spec;
 }
Exemplo n.º 56
0
        public void Test_GetAbsolutePathPathWithError3()
        {
            IRelativeFilePath      directoryPathTo           = @"..\..\Dir1\File.txt".ToRelativeFilePath();
            IAbsoluteDirectoryPath absoluteDirectoryPathFrom = @"C:\Dir1".ToAbsoluteDirectoryPath();

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(absoluteDirectoryPathFrom));
            string failureReason;

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(absoluteDirectoryPathFrom, out failureReason));
            Assert.IsTrue(failureReason == @"Cannot resolve pathTo.TryGetAbsolutePath(pathFrom) because there are too many parent dirs in pathTo:
   PathFrom = ""C:\Dir1""
   PathTo   = ""..\..\Dir1""");
            directoryPathTo.GetAbsolutePathFrom(absoluteDirectoryPathFrom);
        }
Exemplo n.º 57
0
        public void Test_GetRelativePathWithError3()
        {
            IAbsoluteFilePath      filePathTo = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            IAbsoluteDirectoryPath absoluteDirectoryPathFrom = @"D:\Dir1".ToAbsoluteDirectoryPath();

            Assert.IsFalse(filePathTo.CanGetRelativePathFrom(absoluteDirectoryPathFrom));
            string failureReason;

            Assert.IsFalse(filePathTo.CanGetRelativePathFrom(absoluteDirectoryPathFrom, out failureReason));
            Assert.IsTrue(failureReason == @"Cannot compute relative path from 2 paths that are not on the same volume 
   PathFrom = ""D:\Dir1""
   PathTo   = ""C:\Dir1\File.txt""");
            filePathTo.GetRelativePathFrom(absoluteDirectoryPathFrom);
        }
Exemplo n.º 58
0
        static void MigrateServerModFolder(IAbsoluteDirectoryPath modFolder, IAbsoluteDirectoryPath modPath)
        {
            var folderName  = modFolder.DirectoryName;
            var destination = modPath.GetChildDirectoryWithName(folderName);

            if (!destination.Exists)
            {
                Tools.FileUtil.Ops.MoveDirectory(modFolder, destination);
            }
            else
            {
                Directory.Delete(modFolder.ToString(), true);
            }
        }
Exemplo n.º 59
0
        public void Test_PathEquality()
        {
            //
            // RelativeDirectoryPath
            //
            IRelativeDirectoryPath relativeRelativeDirectoryPath1 = @"..\Dir1\Dir2".ToRelativeDirectoryPath();
            IRelativeDirectoryPath relativeRelativeDirectoryPath2 = @"..\\dir1//DIR2/".ToRelativeDirectoryPath();

            Assert.IsTrue(relativeRelativeDirectoryPath1.Equals(relativeRelativeDirectoryPath2));

            relativeRelativeDirectoryPath1 = @"..\Dir1\Dir2".ToRelativeDirectoryPath();
            relativeRelativeDirectoryPath2 = @".\Dir1\Dir2".ToRelativeDirectoryPath();
            Assert.IsFalse(relativeRelativeDirectoryPath1.Equals(relativeRelativeDirectoryPath2));

            relativeRelativeDirectoryPath1 = @"..\Dir1\Dir2".ToRelativeDirectoryPath();
            relativeRelativeDirectoryPath2 = @"..\Dir1\Dir2\Dir3".ToRelativeDirectoryPath();
            Assert.IsFalse(relativeRelativeDirectoryPath1.Equals(relativeRelativeDirectoryPath2));

            relativeRelativeDirectoryPath1 = @"..\Dir1\Dir2".ToRelativeDirectoryPath();
            relativeRelativeDirectoryPath2 = @"..\Dir1\Dir".ToRelativeDirectoryPath();
            Assert.IsFalse(relativeRelativeDirectoryPath1.Equals(relativeRelativeDirectoryPath2));

            //
            // AbsoluteDirectoryPath
            //
            IAbsoluteDirectoryPath absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            IAbsoluteDirectoryPath absoluteAbsoluteDirectoryPath2 = @"C:\\dir1//Dir2\\".ToAbsoluteDirectoryPath();

            Assert.IsTrue(absoluteAbsoluteDirectoryPath1.Equals(absoluteAbsoluteDirectoryPath2));

            absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            absoluteAbsoluteDirectoryPath2 = @"D:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            Assert.IsFalse(absoluteAbsoluteDirectoryPath1.Equals(absoluteAbsoluteDirectoryPath2));

            absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            absoluteAbsoluteDirectoryPath2 = @"C:\Dir1\Dir2\Dir2".ToAbsoluteDirectoryPath();
            Assert.IsFalse(absoluteAbsoluteDirectoryPath1.Equals(absoluteAbsoluteDirectoryPath2));

            absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            absoluteAbsoluteDirectoryPath2 = @"C:\Dir1\Dir".ToAbsoluteDirectoryPath();
            Assert.IsFalse(absoluteAbsoluteDirectoryPath1.Equals(absoluteAbsoluteDirectoryPath2));

            //
            // Mix between AbsoluteDirectoryPath and RelativeDirectoryPath
            //
            relativeRelativeDirectoryPath1 = @"..\Dir1\Dir2".ToRelativeDirectoryPath();
            absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\Dir2".ToAbsoluteDirectoryPath();
            Assert.IsFalse(absoluteAbsoluteDirectoryPath1.Equals(relativeRelativeDirectoryPath1));
        }
			//
			// Path resolving
			//
			public EnvironmentVariableResolvingStatus TryResolve(out IAbsoluteDirectoryPath resolvedPath)
			{
				resolvedPath = null;
				string pathStringResolved;
				if (!TryResolveEnvVar(out pathStringResolved))
				{
					return EnvironmentVariableResolvingStatus.UnresolvedEnvironmentVariable;
				}
				if (!pathStringResolved.IsValidAbsoluteDirectoryPath())
				{
					return EnvironmentVariableResolvingStatus.CannotConvertToAbsolutePath;
				}
				resolvedPath = pathStringResolved.ToAbsoluteDirectoryPath();
				return EnvironmentVariableResolvingStatus.Success;
			}