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;
        }
Exemple #2
0
        public Repository Init(IAbsoluteDirectoryPath directory, RepositoryOperationMode?mode = null)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }

            if (File.Exists(directory.ToString()))
            {
                throw new SynqPathException("Already exists file with same name");
            }

            ConfirmEmpty(directory);

            directory.MakeSurePathExists();
            var repo = new Repository(directory, true);

            try {
                if (mode != null)
                {
                    repo.Config.OperationMode = mode.Value;
                }
                repo.Save();
            } catch {
                repo.Dispose();
                throw;
            }
            return(repo);
        }
Exemple #3
0
            public async Task Install(bool force)
            {
                _destination.MakeSurePathExists();
                var pakFile = _destination.GetChildFileWithName(GetPakName());

                if (!force && pakFile.Exists) // TODO: Date check
                {
                    return;
                }
                if (!_source.Exists)
                {
                    throw new NotFoundException($"{_mod.PackageName} source not found! You might try Diagnosing");
                }

                foreach (var c in _source.DirectoryInfo.EnumerateFiles("*")
                         .Where(x => NDependPathHelpers.ArchiveRx.IsMatch(x.Extension))
                         .Select(x => x.ToAbsoluteFilePath()))
                {
                    c.Unpack(_source, true);
                }

                var modInfo = EnumerateMatchingFiles("modinfo.xml").FirstOrDefault();

                if ((modInfo != null) && modInfo.Exists)
                {
                    await HandleAsModInfoBasedMod(modInfo).ConfigureAwait(false);
                }
                else
                {
                    await HandleFileBasedMod(pakFile).ConfigureAwait(false);
                }
            }
Exemple #4
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);
        }
        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;
        }
Exemple #6
0
 public void BackupScriptHook()
 {
     _gameLocalDataFolder.MakeSurePathExists();
     foreach (var f in scriptHookFiles)
     {
         _state.Directory.GetChildFileWithName(f).Copy(_gameLocalDataFolder.GetChildFileWithName(f));
     }
 }
 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"));
     //}
 }
        public void MoveModFolders(IAbsoluteDirectoryPath oldModsPath, IAbsoluteDirectoryPath newModsPath) {
            newModsPath.MakeSurePathExists();

            foreach (var dir in Directory.EnumerateDirectories(oldModsPath.ToString())
                .Where(x => !excludeFolders.Contains(Path.GetFileName(x).ToLower()))
                .Where(x => File.Exists(Path.Combine(x, Package.SynqInfoFile)) ||
                            Directory.Exists(Path.Combine(x, Repository.RepoFolderName))))
                TryMoveDir(dir.ToAbsoluteDirectoryPath(), newModsPath);
        }
Exemple #9
0
            public async Task Install()
            {
                _installPath.MakeSurePathExists();

                foreach (var f in _sourceDir.DirectoryInfo.EnumerateFiles())
                {
                    await f.ToAbsoluteFilePath().CopyAsync(_installPath).ConfigureAwait(false);
                }
            }
Exemple #10
0
            protected override async Task InstallImpl(bool force)
            {
                _installPath.MakeSurePathExists();

                foreach (var f in SourcePath.DirectoryInfo.EnumerateFiles())
                {
                    await f.ToAbsoluteFilePath().CopyAsync(_installPath).ConfigureAwait(false);
                }
            }
 public async Task Install(IAbsoluteDirectoryPath destination, Settings settings,
     params IAbsoluteFilePath[] files) {
     destination.MakeSurePathExists();
     foreach (var f in files)
         await f.CopyAsync(destination).ConfigureAwait(false);
     var theShell = GetTheShell(destination, files);
     RunSrm(theShell, "install", "-codebase");
     await RestartExplorer().ConfigureAwait(false);
     settings.ExtensionInstalled();
 }
Exemple #12
0
 static void UnpackArchive(IAbsoluteFilePath sourceFile, IAbsoluteDirectoryPath outputFolder, bool overwrite,
     bool checkFileIntegrity,
     SevenZipExtractor extracter) {
     if (checkFileIntegrity && !extracter.Check())
         throw new Exception(String.Format("Appears to be an invalid archive: {0}", sourceFile));
     outputFolder.MakeSurePathExists();
     extracter.ExtractFiles(outputFolder.ToString(), overwrite
         ? extracter.ArchiveFileNames.ToArray()
         : extracter.ArchiveFileNames.Where(x => !outputFolder.GetChildFileWithName(x).Exists)
             .ToArray());
 }
 async Task DownloadFileAsync(string remoteFile, IAbsoluteDirectoryPath destinationPath,
                              IMirrorSelector scoreMirrorSelector, CancellationToken token)
 {
     destinationPath.MakeSurePathExists();
     using (var dl = _createMultiMirrorFileDownloader(scoreMirrorSelector)) {
         await
         dl.Value.DownloadAsync(new MultiMirrorFileDownloadSpec(remoteFile,
                                                                destinationPath.GetChildFileWithName(remoteFile)) { CancellationToken = token }, token)
         .ConfigureAwait(false);
     }
 }
Exemple #14
0
        public void MoveModFolders(IAbsoluteDirectoryPath oldModsPath, IAbsoluteDirectoryPath newModsPath)
        {
            newModsPath.MakeSurePathExists();

            foreach (var dir in Directory.EnumerateDirectories(oldModsPath.ToString())
                     .Where(x => !excludeFolders.Contains(Path.GetFileName(x).ToLower()))
                     .Where(x => File.Exists(Path.Combine(x, Package.SynqInfoFile)) ||
                            Directory.Exists(Path.Combine(x, Repository.RepoFolderName))))
            {
                TryMoveDir(dir.ToAbsoluteDirectoryPath(), newModsPath);
            }
        }
 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);
         }
 }
Exemple #16
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);
                        }
                    }
                }
Exemple #17
0
            protected override async Task InstallImpl(bool force)
            {
                _modDir.MakeSurePathExists();
                var exts        = new[] { ".pak", ".modpak" };
                var destPakFile = _modDir.GetChildFileWithName($"{Mod.PackageName}.pak");

                if (!force && destPakFile.Exists) // TODO: Date check
                {
                    return;
                }

                // TODO: Support mods without Paks, as folder ? Or mark as not-installable
                var sourcePakFiles =
                    exts.SelectMany(x => SourcePath.DirectoryInfo.EnumerateFiles($"*{x}", SearchOption.AllDirectories))
                    .Select(x => x.ToAbsoluteFilePath()).ToArray();
                var sourcePak = sourcePakFiles.FirstOrDefault();
                IAbsoluteFilePath sourcePakPath;

                if ((sourcePak == null) || !sourcePak.Exists)
                {
                    var modInfo =
                        SourcePath.DirectoryInfo.EnumerateFiles("*.modinfo", SearchOption.AllDirectories)
                        .FirstOrDefault();
                    if (modInfo != null)
                    {
                        sourcePakPath = await PackModInfoMod(modInfo.ToAbsoluteFilePath()).ConfigureAwait(false);
                    }
                    else
                    {
                        var metadata =
                            SourcePath.DirectoryInfo.EnumerateFiles(".metadata", SearchOption.AllDirectories)
                            .FirstOrDefault();
                        if (metadata == null)
                        {
                            throw new NotInstallableException(
                                      $"{Mod.PackageName} source .pak not found! You might try Diagnosing");
                        }
                        sourcePakPath = await PackMetadataMod(metadata.ToAbsoluteFilePath()).ConfigureAwait(false);
                    }
                }
                else
                {
                    sourcePakPath = sourcePak;
                }
                await sourcePakPath.CopyAsync(destPakFile).ConfigureAwait(false);

                var bak = GetBackupFile(destPakFile);

                bak.DeleteIfExists();
            }
        public Repository Init(IAbsoluteDirectoryPath directory, RepositoryOperationMode? mode = null) {
            Contract.Requires<ArgumentNullException>(directory != null);

            if (File.Exists(directory.ToString()))
                throw new SynqPathException("Already exists file with same name");

            ConfirmEmpty(directory);

            directory.MakeSurePathExists();
            var repo = new Repository(directory, true);
            if (mode != null)
                repo.Config.OperationMode = mode.Value;
            repo.Save();
            return repo;
        }
        void ExtractFolder(IAbsoluteDirectoryPath rootPath, IAbsoluteDirectoryPath tempPath,
                           IAbsoluteDirectoryPath destination, IStatus status)
        {
            destination = destination.GetChildDirectoryWithName("addons");
            destination.MakeSurePathExists();
            var files = Directory.GetFiles(Path.Combine(rootPath.ToString(), "addons"), "*.ifa");
            var i     = 0;

            foreach (var f in files)
            {
                ProcessPbo(f, tempPath, destination);
                i++;
                status.Update(null, (double)i / files.Length * 100);
            }
        }
        public async Task Install(IAbsoluteDirectoryPath destination, Settings settings,
                                  params IAbsoluteFilePath[] files)
        {
            destination.MakeSurePathExists();
            foreach (var f in files)
            {
                await f.CopyAsync(destination).ConfigureAwait(false);
            }
            var theShell = GetTheShell(destination, files);

            RunSrm(theShell, "install", "-codebase");
            await RestartExplorer().ConfigureAwait(false);

            settings.ExtensionInstalled();
        }
Exemple #21
0
                public void CopyDirectoryWithRetry(IAbsoluteDirectoryPath sourceFolder,
                                                   IAbsoluteDirectoryPath outputFolder, bool overwrite = false)
                {
                    var di = sourceFolder.DirectoryInfo;

                    outputFolder.MakeSurePathExists();
                    CopyDirectoryFilesWithRetry(outputFolder, di, overwrite);

                    foreach (var directory in di.EnumerateDirectories("*.*", SearchOption.AllDirectories))
                    {
                        CopyDirectoryFilesWithRetry(
                            outputFolder.GetChildDirectoryWithName(directory.FullName.Replace(sourceFolder + "\\",
                                                                                              string.Empty)),
                            directory, overwrite);
                    }
                }
        public PackageManager(Repository repo, IAbsoluteDirectoryPath workDir, StatusRepo statusRepo,
                              bool createWhenNotExisting = false,
                              string remote = null)
        {
            if (repo == null)
            {
                throw new ArgumentNullException(nameof(repo));
            }
            if (workDir == null)
            {
                throw new ArgumentNullException(nameof(workDir));
            }
            WorkDir    = workDir;
            StatusRepo = statusRepo;
            Repo       = repo;
            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;
        }
Exemple #23
0
            protected override async Task InstallImpl(bool force)
            {
                var modName = GetModName();

                _modPath.MakeSurePathExists();
                var destinationDir = _modPath.GetChildDirectoryWithName(modName);

                if (destinationDir.Exists)
                {
                    destinationDir.Delete(true);
                }
                SourceZip.Unpack(destinationDir, true);

                var desc    = destinationDir.GetChildFileWithName("descriptor.mod");
                var modFile = _modPath.GetChildFileWithName($"{modName}.mod");

                modFile.WriteText(
                    desc.ReadAllText()
                    .Replace($"archive=\"{modName}.zip\"", $"path=\"{GetRelModName()}\""));
            }
Exemple #24
0
 public TmpDirectory(IAbsoluteDirectoryPath path) {
     path.MakeSurePathExists();
     _path = path;
 }
Exemple #25
0
 public TmpDirectory(IAbsoluteDirectoryPath path)
 {
     path.MakeSurePathExists();
     _path = path;
 }
 void ExtractFolder(IAbsoluteDirectoryPath rootPath, IAbsoluteDirectoryPath tempPath,
     IAbsoluteDirectoryPath destination, IStatus status) {
     destination = destination.GetChildDirectoryWithName("addons");
     destination.MakeSurePathExists();
     var files = Directory.GetFiles(Path.Combine(rootPath.ToString(), "addons"), "*.ifa");
     var i = 0;
     foreach (var f in files) {
         ProcessPbo(f, tempPath, destination);
         i++;
         status.Update(null, ((double)i / files.Length) * 100);
     }
 }
 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);
     }
 }
 async Task DownloadFileAsync(string remoteFile, IAbsoluteDirectoryPath destinationPath,
     ExportLifetimeContext<IMirrorSelector> scoreMirrorSelector, CancellationToken token) {
     destinationPath.MakeSurePathExists();
     using (var dl = _createMultiMirrorFileDownloader(scoreMirrorSelector.Value)) {
         await
             dl.Value.DownloadAsync(new MultiMirrorFileDownloadSpec(remoteFile,
                 destinationPath.GetChildFileWithName(remoteFile)) {CancellationToken = token}, token)
                 .ConfigureAwait(false);
     }
 }
 async Task DownloadFilesAsync(StatusRepo sr,
     IDictionary<KeyValuePair<string, Func<IAbsoluteFilePath, bool>>, ITransferStatus> transferStatuses,
     IAbsoluteDirectoryPath destinationPath, ExportLifetimeContext<IMirrorSelector> scoreMirrorSelector) {
     destinationPath.MakeSurePathExists();
     sr.Total = transferStatuses.Count;
     using (var multiMirrorFileDownloader = _createMultiMirrorFileDownloader(scoreMirrorSelector.Value))
     using (var multi = _createQueueDownloader(multiMirrorFileDownloader.Value)) {
         await multi.Value
             .DownloadAsync(CreateFileQueueSpec(transferStatuses, destinationPath), sr.CancelToken)
             .ConfigureAwait(false);
     }
 }
 async Task DownloadFileAsync(string remoteFile, IAbsoluteDirectoryPath destinationPath,
     ExportLifetimeContext<IMirrorSelector> scoreMirrorSelector, CancellationToken token,
     Func<IAbsoluteFilePath, bool> confirmValidity, int zsyncHttpFallbackAfter) {
     destinationPath.MakeSurePathExists();
     using (var dl = _createMultiMirrorFileDownloader(scoreMirrorSelector.Value)) {
         await
             dl.Value.DownloadAsync(new MultiMirrorFileDownloadSpec(remoteFile,
                 destinationPath.GetChildFileWithName(remoteFile), confirmValidity) {
                     CancellationToken = token,
                     Progress = new TransferStatus(remoteFile) {ZsyncHttpFallbackAfter = zsyncHttpFallbackAfter}
                 },
                 token).ConfigureAwait(false);
     }
 }