コード例 #1
0
        public bool ApplyUpdate()
        {
            try
            {
                Console.WriteLine("HellionExtendedServer:  Applying Update...");

                string updatePath = Globals.GetFolderPath(HESFolderName.Updates);
                string hesPath    = Globals.GetFolderPath(HESFolderName.Hes);

                // for all of the files already in the server folder
                foreach (var file in CurrentFileList)
                {
                    // if the old file has an updated version
                    if (FileList.Exists(x => x.Name == file.Name))
                    {
                        var newFile  = FileList.Find(x => x.Name == file.Name);
                        var fullName = Path.GetFullPath(file.FullName);

                        // rename old file if the file exists
                        if (File.Exists(fullName))
                        {
                            File.Move(fullName, fullName + ".old");
                        }

                        // move new file if it doesn't already exist
                        if (!File.Exists(fullName) && File.Exists(Path.GetFullPath(newFile.FullName)))
                        {
                            File.Move(Path.GetFullPath(newFile.FullName), fullName);
                        }
                    }
                }

                if (Config.Instance.Settings.AutoRestartsEnable && !GUIMode)
                {
                    HES.Restart();
                }

                OnUpdateApplied?.Invoke(m_useDevRelease ? m_developmentRelease : m_currentRelease);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("HellionExtendedServer:  Update Failed (ApplyUpdate)" + ex.ToString());
            }
            return(false);
        }
コード例 #2
0
        private void ReleaseDownloaded(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {
                FileList.ForEach((file) => file.Delete());
                FileList.Clear();

                string updatePath = Globals.GetFolderPath(HESFolderName.Updates);

                File.WriteAllBytes(Path.Combine(updatePath, UpdateFileName), e.Result);
                ZipFile.ExtractToDirectory(Path.Combine(updatePath, UpdateFileName), updatePath);
                File.Delete(Path.Combine(updatePath, UpdateFileName));
                Console.WriteLine("HellionExtendedServer:  Update has been downloaded!");

                foreach (string file in Directory.GetFiles(updatePath, "*", SearchOption.AllDirectories))
                {
                    FileList.Add(new FileInfo(file));
                }

                OnUpdateDownloaded?.Invoke(m_useDevRelease ? m_developmentRelease : m_currentRelease);

                if (!GUIMode)
                {
                    ApplyUpdate();
                    Console.WriteLine("HellionExtendedServer:  Update has been applied. Please restart HellionExtendedServer.exe to finish the update!");

                    if (ServerInstance.Instance != null)
                    {
                        HES.Restart(ServerInstance.Instance.IsRunning);
                    }
                    else
                    {
                        HES.Restart(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("HellionExtendedServer:  Update Failed (ReleaseDownloadedEvent)" + ex.ToString());
            }
        }