public void Install(IEnumerable <ComponentInfo> components, string exe_path = null)
        {
            exe_path = _GetExePath(exe_path);

            var real_components = new List <ComponentVersion>();
            var used_components = new HashSet <ETGModComponent>();
            var gungeon_version = Autodetector.GetVersionIn(exe_path);

            foreach (var com in components)
            {
                ETGModComponent component = _Downloader.TryGet(com.Name.Trim());

                if (component != null)
                {
                    if (used_components.Contains(component))
                    {
                        throw new InstallationFailedException($"Duplicate {component.Name} component.");
                    }
                    used_components.Add(component);

                    ETGModVersion version = null;
                    if (com.Version == null)
                    {
                        version = component.Versions[0];
                    }
                    else
                    {
                        foreach (var ver in component.Versions)
                        {
                            if (ver.Key == com.Version.Trim())
                            {
                                version = ver;
                                break;
                            }
                        }
                        if (version == null)
                        {
                            throw new InstallationFailedException($"Version {com.Version} of component {com.Name} doesn't exist.");
                        }
                    }

                    real_components.Add(new ComponentVersion(component, version));
                }
                else
                {
                    throw new InstallationFailedException($"Component {com.Name} doesn't exist in the list of components.");
                }
            }
            Install(real_components, exe_path);
        }
        public void Install(IEnumerable <ComponentVersion> components, string exe_path = null, Action <ComponentVersion> component_installed = null)
        {
            exe_path = _GetExePath(exe_path);
            _Installer.ChangeExePath(exe_path);

            _Logger.Info($"OPERATION: Install. Target: {exe_path}");

            var used_components = new HashSet <ETGModComponent>();
            var gungeon_version = Autodetector.GetVersionIn(exe_path);

            if (!Options.HasFlag(InstallerOptions.ForceBackup))
            {
                _Installer.Restore();
            }
            _Installer.Backup(Options.HasFlag(InstallerOptions.ForceBackup));

            foreach (var pair in components)
            {
                using (var build = _Downloader.Download(pair.Version)) {
                    var installable = new Installer.InstallableComponent(pair.Component, pair.Version, build);
                    if (!Options.HasFlag(InstallerOptions.SkipVersionChecks))
                    {
                        try {
                            installable.ValidateGungeonVersion(gungeon_version);
                        } catch (Installer.InstallableComponent.VersionMismatchException e) {
                            throw new InstallationFailedException(e.Message);
                        }
                    }

                    _Installer.InstallComponent(installable, Options.HasFlag(InstallerOptions.LeavePatchDLLs));
                    if (component_installed != null)
                    {
                        component_installed.Invoke(pair);
                    }
                }
            }

            _Logger.Info($"OPERATION COMPLETED SUCCESSFULLY");
        }
Beispiel #3
0
        public void Backup(bool force = false)
        {
            if (Directory.Exists(BackupDir))
            {
                if (force)
                {
                    Directory.Delete(BackupDir, recursive: true);
                }
                else
                {
                    if (!Directory.Exists(BackupRootDir))
                    {
                        _Logger.Warn("Backup directory exists, but the root backup subdirectory is missing - did an error occure while creating the backup? The game files might be corrupted.");
                    }
                    if (!Directory.Exists(BackupManagedDir))
                    {
                        _Logger.Warn("Backup directory exists, but the managed backup subdirectory is missing - did an error occure while creating the backup? The game files might be corrupted.");
                    }
                    if (!Directory.Exists(BackupPluginsDir))
                    {
                        _Logger.Warn("Backup directory exists, but the plugins backup subdirectory is missing - did an error occure while creating the backup? The game files might be corrupted.");
                    }

                    _Logger.Info($"Backup folder exists - not backing up");
                    return;
                }
            }

            var game_version = Autodetector.GetVersionIn(ExeFile);

            if (game_version == null)
            {
                throw new Exception("Missing version.txt file!");
            }

            _Logger.Info("Performing backup");

            Directory.CreateDirectory(BackupDir);
            Directory.CreateDirectory(BackupRootDir);
            Directory.CreateDirectory(BackupMonoDir);
            Directory.CreateDirectory(BackupManagedDir);
            Directory.CreateDirectory(BackupPluginsDir);

            File.Copy(BootConfigFile, BackupBootConfigFile, overwrite: true);

            var root_entries = Directory.GetFileSystemEntries(GameDir);

            foreach (var ent in root_entries)
            {
                var file = Path.GetFileName(ent);
                if (Downloader.GungeonMetadata.Executables.Contains(file))
                {
                    _Logger.Debug($"Backing up root file: {file}");

                    File.Copy(ent, Path.Combine(BackupRootDir, file), overwrite: true);
                }
            }

            var mono_entries = Directory.GetFileSystemEntries(MonoDir);

            foreach (var ent in mono_entries)
            {
                var file = Path.GetFileName(ent);
                _Logger.Debug($"Backing up mono file: {file}");

                File.Copy(ent, Path.Combine(BackupMonoDir, file), overwrite: true);
            }

            var managed_entries = Directory.GetFileSystemEntries(ManagedDir);

            foreach (var ent in managed_entries)
            {
                var file = Path.GetFileName(ent);
                if (Downloader.GungeonMetadata.ManagedFiles.Contains(file))
                {
                    _Logger.Debug($"Backing up managed file: {file}");

                    File.Copy(ent, Path.Combine(BackupManagedDir, file), overwrite: true);
                }
            }

            var plugins_entries = Directory.GetFileSystemEntries(PluginsDir);

            foreach (var ent in plugins_entries)
            {
                var file = Path.GetFileName(ent);
                // TODO filter?
                _Logger.Debug($"Backing up plugins file: {file}");

                Utils.CopyRecursive(ent, Path.Combine(BackupPluginsDir, file));
            }

            _Logger.Debug($"Backed up for Gungeon {game_version}");
            File.WriteAllText(BackupVersionFile, game_version);
        }
Beispiel #4
0
        public void Restore(bool force = false)
        {
            if (!force && !Directory.Exists(BackupDir))
            {
                _Logger.Info($"Backup doesn't exist - not restoring");
                return;
            }

            _Logger.Info("Restoring from backup");

            var game_version = Autodetector.GetVersionIn(ExeFile);

            if (game_version == null)
            {
                throw new Exception("Missing version.txt file!");
            }

            if (!File.Exists(BackupVersionFile))
            {
                _Logger.Warn("Backup version file is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                var ver = File.ReadAllText(BackupVersionFile);
                if (ver == game_version)
                {
                    _Logger.Debug($"Backup versions match");
                }
                else
                {
                    _Logger.Debug($"Backup versions DON'T match");
                    try {
                        var bkp_ver_obj = new Version(ver);
                        var cur_ver_obj = new Version(game_version);

                        if (cur_ver_obj > bkp_ver_obj)
                        {
                            _Logger.Info($"Backup version is older - assuming game was updated, wiping backup directory so that a new backup can be made");
                        }
                        else
                        {
                            _Logger.Warn($"Game version is older than the current backup - did you downgrade? Trying to carry on by wiping the backup directory so that a new backup can be made...");
                        }
                    } catch {
                        _Logger.Warn("Exception while comparing versions (did the Gungeon versioning scheme change?). This is probably bad. Assuming update, wiping backup directory so that a new backup can be made");
                    }
                    Directory.Delete(BackupDir, recursive: true);
                    return;
                }
            }

            if (!Directory.Exists(BackupBootConfigFile))
            {
                _Logger.Warn("Boot file backup is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                File.Delete(BootConfigFile);
                _Logger.Debug($"Restoring boot.config file");

                File.Copy(BackupBootConfigFile, BootConfigFile);
            }

            if (File.Exists(PatchedExeFile))
            {
                _Logger.Info($"Removing old temporary patched executable");
                File.Delete(PatchedExeFile);
            }

            if (!Directory.Exists(BackupRootDir))
            {
                _Logger.Warn("Root directory backup is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                var root_entries = Directory.GetFileSystemEntries(BackupRootDir);

                foreach (var ent in root_entries)
                {
                    var file = Path.GetFileName(ent);

                    _Logger.Debug($"Restoring root file: {file}");

                    var target = Path.Combine(GameDir, file);
                    if (File.Exists(target))
                    {
                        File.Delete(target);
                    }
                    File.Copy(ent, target);
                }
            }

            if (!Directory.Exists(BackupMonoDir))
            {
                _Logger.Warn("Mono directory backup is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                _Logger.Debug($"WIPING Mono directory");
                Directory.Delete(MonoDir, recursive: true);

                Directory.CreateDirectory(MonoDir);

                var managed_entries = Directory.GetFileSystemEntries(BackupMonoDir);

                foreach (var ent in managed_entries)
                {
                    var file = Path.GetFileName(ent);

                    _Logger.Debug($"Restoring mono file: {file}");

                    File.Copy(ent, Path.Combine(MonoDir, file), overwrite: true);
                }
            }

            if (!Directory.Exists(BackupManagedDir))
            {
                _Logger.Warn("Managed directory backup is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                _Logger.Debug($"WIPING Managed directory");
                Directory.Delete(ManagedDir, recursive: true);

                Directory.CreateDirectory(ManagedDir);

                var managed_entries = Directory.GetFileSystemEntries(BackupManagedDir);

                foreach (var ent in managed_entries)
                {
                    var file = Path.GetFileName(ent);

                    _Logger.Debug($"Restoring managed file: {file}");

                    File.Copy(ent, Path.Combine(ManagedDir, file), overwrite: true);
                }
            }

            if (!Directory.Exists(BackupPluginsDir))
            {
                _Logger.Warn("Plugins directory backup is missing - did an error occur while creating the backup? The game files might be corrupted.");
            }
            else
            {
                _Logger.Debug($"WIPING Plugins directory");
                Directory.Delete(PluginsDir, recursive: true);

                Directory.CreateDirectory(PluginsDir);

                var plugins_entries = Directory.GetFileSystemEntries(BackupPluginsDir);

                foreach (var ent in plugins_entries)
                {
                    var file = Path.GetFileName(ent);

                    _Logger.Debug($"Restoring plugins file/directory: {file}");

                    Utils.CopyRecursive(ent, Path.Combine(PluginsDir, file));
                }
            }
        }