Пример #1
0
        private static bool BackupApplication(ApplicationObject application)
        {
            var backupDirectory = Settings.My.BackupDirectory;

            var applicationBackupDirectory = Path.Combine(backupDirectory, application.Type, string.Format("{0}.{1:yyyyMMdd}", application.Name, DateTime.Now));

            if (Directory.Exists(applicationBackupDirectory))
            {
                return(false);
            }

            Directory2.CopyDirectory(application.FullPath, applicationBackupDirectory, true);

            LoadBackupVersions(backupDirectory, application);

            var deleteBackupVersions = application.Backups.Skip(Settings.My.ApplicationMaxBackups).ToArray();

            if (deleteBackupVersions.Any())
            {
                foreach (var backup in deleteBackupVersions)
                {
                    if (Directory.Exists(backup.FullPath))
                    {
                        Directory.Delete(backup.FullPath, true);
                    }
                    application.Backups.Remove(backup);
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// What the task must do
        /// </summary>
        internal static void Run()
        {
            // 1. Mods parent folder
            DirectoryInfo di = new DirectoryInfo(InstallHelper.BasePath);

            if (!di.Exists)
            {
                di.Create();
            }

            // 2. Current slot folder
            string slotRef = InstallHelper.CurrentPatch.SlotRef;

            if (string.IsNullOrEmpty(slotRef))
            {
                slotRef = Tools.KEY_MISC_SLOT;
            }

            _SlotFolder = string.Concat(InstallHelper.BasePath, slotRef, @"\");
            di          = new DirectoryInfo(_SlotFolder);

            if (!di.Exists)
            {
                di.Create();
            }

            // Creates folders for backup
            _CreatePartFolders(_SlotFolder);

            // 3. Current mod folder
            _ModFolder = InstallHelper.CurrentPatch.Name;

            if (string.IsNullOrEmpty(_ModFolder))
            {
                Log.Info("Warning: current mod has no name. Please provide one in the future... now using NONAME");
                _ModFolder = InstallHelper.DEFAULT_MOD_NAME;
            }
            else
            {
                _ModFolder = Directory2.GetCleanName(_ModFolder);
            }

            di = new DirectoryInfo(_SlotFolder + _ModFolder);

            if (!di.Exists)
            {
                di.Create();
            }

            // 4. Parts folders
            _CreatePartFolders(di.FullName);

            // 5. Remapping
            Directory.CreateDirectory(InstallHelper.RemapPath);
            InstallHelper.RemappedFiles.Clear();

            // Folder information
            InstallHelper.SlotPath = _SlotFolder + @"\";
            InstallHelper.ModPath  = di.FullName + @"\";
        }
Пример #3
0
        public bool Install(
            string rootFolder, string packagePath, string version, string executableName, string componentDisplayName, string webApiUrl, string certificateSubject,
            ILogger logger = null)
        {
            var transactionStore = new NoTransactionStore();
            var selfControl      = new NoSelfControl();

            var workingDirectory = Path.Combine(rootFolder, "temp");

            try
            {
                Directory2.CreateIfNotExists(workingDirectory);

                var environment = new InstallationEnvironment(
                    workingDirectory,
                    Path.Combine(rootFolder, "wwwroot"),
                    new CertificateSubjectMatcher(certificateSubject));

                var componentPath = Path.Combine(rootFolder, $"Shell_{version}");
                var packageData   = new Package {
                    Id = 0, Path = packagePath
                };
                var componentData = new Component
                {
                    Myself = false,
                    InitialInstallation = true,
                    CurrentVersion      = null,
                    ServiceName         = null,
                    NewServiceName      = $"Acr_SiteServer_Shell_{version.Replace(".", "_")}",
                    DistrPath           = null,
                    NewDistrPath        = componentPath,
                    Executable          = null,
                    NewExecutable       = executableName,
                    WwwPath             = $"Shell_{version}",
                    NewWwwPath          = $"Shell_{version}",
                    DisplayName         = $"ACR Site Server: {componentDisplayName} (version {version})",
                    Args = new Dictionary <string, string>
                    {
                        { "webapi", webApiUrl },
                    },
                    AdditionalWebFiles = null,
                };

                return(FlowBuilder.Install(componentData, packageData, environment, selfControl)
                       .WithDefaultManifestHashAlgorithm("SHA1")
                       .Build()
                       .Execute(logger, transactionStore));
            }
            finally
            {
                Directory2.DeleteIfExists(workingDirectory);
            }
        }
Пример #4
0
        public bool Uninstall(string rootFolder, string currentVersion, string executableName, string webApiUrl,
                              ILogger logger = null)
        {
            var transactionStore = new NoTransactionStore();

            var workingDirectory = Path.Combine(rootFolder, "temp");

            try
            {
                Directory2.CreateIfNotExists(workingDirectory);
                var environment = new InstallationEnvironment(
                    Directory.GetCurrentDirectory(),
                    Path.Combine(rootFolder, "wwwroot"),
                    new CertificateSubjectMatcher(""));

                var componentPath = Path.Combine(rootFolder, $"Shell_{currentVersion}");
                var serviceName   = $"Acr_SiteServer_Shell_{currentVersion.Replace(".", "_")}";

                var serviceController = GetService(serviceName);

                var componentData = new Component
                {
                    CurrentVersion = null,
                    ServiceName    = serviceName,
                    DistrPath      = componentPath,
                    Executable     = executableName,
                    WwwPath        = $"Shell_{currentVersion}",
                    DisplayName    = serviceController != null ? serviceController.DisplayName : $"ACR Site Server: Shell (version {currentVersion})",
                    Args           = new Dictionary <string, string>
                    {
                        { "webapi", webApiUrl },
                    },
                    AdditionalWebFiles = null,
                };

                var uninstalled = FlowBuilder.Uninstall(componentData, environment)
                                  .Build()
                                  .Execute(logger, transactionStore);
                if (uninstalled)
                {
                    Directory2.DeleteIfExists(Path.Combine(rootFolder, "wwwroot"));
                    Directory2.DeleteIfExists(Path.Combine(rootFolder, "Acr_SiteServer_ShellDb"));
                    Directory2.DeleteIfExists(Path.Combine(rootFolder, "ShellDb"));
                }
                return(uninstalled);
            }
            finally
            {
                Directory2.DeleteIfExists(workingDirectory);
            }
        }
Пример #5
0
        public void Compare()
        {
            Dictionary <string, Item> items = new Dictionary <string, Item> ();
            var s1 = Directory1.FullName.Length;

            foreach (var file in Directory1.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var fullname = GetRootName(file, s1);
                var key      = GetKey(fullname);
                items.Add(key, new Item()
                {
                    Directory = Path.GetDirectoryName(fullname),
                    Name      = Path.GetFileName(file.Name),
                    Info1     = file,
                });
            }
            // process 2nd directory
            var s2 = Directory2.FullName.Length;

            foreach (var file in Directory2.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var  fullname = GetRootName(file, s2);
                var  key      = GetKey(fullname);
                Item item;
                if (!items.TryGetValue(key, out item))
                {
                    item = new Item()
                    {
                        Directory = Path.GetDirectoryName(fullname),
                        Name      = Path.GetFileName(file.Name),
                    };
                    items.Add(key, item);
                }
                item.Info2 = file;
            }

            // display
            Start();
            foreach (var kvp in items.OrderBy((arg) => arg.Key))
            {
                Process(kvp.Value);
            }
            End();
        }