public UpdateManager()
        {
            mainLog = NLog.LogManager.GetCurrentClassLogger();

            m_instance = this;

            ServicePointManager.DefaultConnectionLimit = 10;

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

            foreach (string file in Directory.GetFiles(FolderStructure.RootFolderPath, "*", SearchOption.AllDirectories))
            {
                var currentFile = new FileInfo(file);

                if (currentFile.Extension == ".old")
                {
                    currentFile.Delete();
                }

                if (file.Contains("updates") || file.Contains("temp"))
                {
                    continue;
                }

                CurrentFileList.Add(currentFile);
            }

            CheckForUpdates().GetAwaiter().GetResult();
        }
        private void ReleaseDownloaded(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {
                FileList.ForEach((file) => file.Delete());
                FileList.Clear();

                string updatePath = ExtenderGlobals.GetFolderPath(IRSEFolderName.Updates);

                File.WriteAllBytes(Path.Combine(updatePath, UpdateFileName), e.Result);
                ZipFile.ExtractToDirectory(Path.Combine(updatePath, UpdateFileName), updatePath);
                File.Delete(Path.Combine(updatePath, UpdateFileName));
                Console.WriteLine("IRSE:  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("IRSE:  Update has been applied. Please restart IRSE.exe to finish the update!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("IRSE:  Update Failed (ReleaseDownloadedEvent)" + ex.ToString());
            }
        }
Beispiel #3
0
        private void ReleaseDownloaded(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {
                FileList.ForEach((file) => file.Delete());
                FileList.Clear();

                string updatePath = ExtenderGlobals.GetFolderPath(IRSEFolderName.Updates);

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

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

                OnUpdateDownloaded?.Invoke(m_useDevRelease ? DevelopmentRelease : CurrentRelease);

                if (!GUIMode)
                {
                    ApplyUpdate();
                    Console.WriteLine("IRSE:  Update has been applied.");

                    if (Config.Instance.Settings.AutoRestartsEnable)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("IRSE:  Auto-Restarts enabled. Restarting...");
                        Program.Restart();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("IRSE:  Press Y to restart IRSE. or N if you want to restart later.");
                        Console.ResetColor();

                        switch (Console.ReadKey().Key)
                        {
                        case ConsoleKey.Y:
                            Program.Restart();
                            break;

                        case ConsoleKey.N:
                            break;

                        default:
                            break;
                        }
                    }
                }

                UpdaterDone = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("IRSE:  Update Failed (ReleaseDownloadedEvent)" + ex.ToString());
            }
        }
Beispiel #4
0
        public void Build()
        {
            try
            {
                foreach (string resource in _assembly.GetManifestResourceNames())
                {
                    using (Stream stream = _assembly.GetManifestResourceStream(resource))
                    {
                        string fileName = resource.Replace("IRSE.Resources.", "");

                        if (fileName.StartsWith("IRSE."))
                        {
                            continue;
                        }

                        string path = string.Empty;
                        switch (Path.GetExtension(resource))
                        {
                        case ".dll":
                            path = ExtenderGlobals.GetFolderPath(IRSEFolderName.Bin);
                            break;

                        case ".ini":
                        case ".config":
                        case ".json":
                            path = ExtenderGlobals.GetFolderPath(IRSEFolderName.Config);
                            break;

                        default:
                            break;
                        }

                        if (string.IsNullOrEmpty(path))
                        {
                            continue;
                        }

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        //TODO if a config file already exists
                        if (!File.Exists(Path.Combine(path, fileName)))
                        {
                            byte[] data = new byte[stream.Length];
                            stream.Read(data, 0, data.Length);

                            File.WriteAllBytes(Path.Combine(path, fileName), data);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[ERROR] IRSE: [{ex.TargetSite}]: {ex.StackTrace}");
            }
        }
Beispiel #5
0
        public bool ApplyUpdate()
        {
            try
            {
                Console.WriteLine("IRSE:  Applying Update...");

                string updatePath = ExtenderGlobals.GetFolderPath(IRSEFolderName.Updates);
                string IRSEPath   = ExtenderGlobals.GetFolderPath(IRSEFolderName.IRSE);

                // 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 (EnableAutoRestarts)
                {
                    Program.Restart();
                }

                OnUpdateApplied?.Invoke(m_useDevRelease ? DevelopmentRelease : CurrentRelease);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("IRSE:  Update Failed (ApplyUpdate)" + ex.ToString());
            }
            return(false);
        }