Пример #1
0
        internal static async Task RunUpdater(bool manual /*int waitTime = 0*/)
        {
            running = true;
            //if (waitTime != 0) await Task.Delay(waitTime);
            Log.Info("Starting AutoUpdater");
            using (var client = new WebClient())
            {
                var nv = await client.DownloadStringTaskAsync("https://raw.githubusercontent.com/hippo9799/advanced-server-tools/master/version.txt");

                if (nv == null)
                {
                    Log.Error("Failed to get new version");
                    running = false;
                    return;
                }
                if (nv == Version)
                {
                    if (manual || AdvSrvTools.Instance.Config.VerboseMode)
                    {
                        Log.Warn("Plugin already to the lastest version!");
                    }
                    running = false;
                    return;
                }
                if (AdvSrvTools.Instance.Config.VerboseMode)
                {
                    Log.Info($"Got new version: {nv}");
                }

                string assemblyFolder = new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;
                if (assemblyFolder.StartsWith("file:\\"))
                {
                    assemblyFolder = assemblyFolder.Remove(0, 6);
                }
                var location = Path.Combine(assemblyFolder, "AdvSrvTools.dll");
                if (!File.Exists(location))
                {
                    Log.Error("The updater could not determine the plugin path. Make sure the plugin is named \"AdvSrvTools.dll\".");
                    running = false;
                    return;
                }
                if (AdvSrvTools.Instance.Config.VerboseMode)
                {
                    Log.Info($"Plugin path: {location}");
                }

                await client.DownloadFileTaskAsync("https://github.com/hippo9799/advanced-server-tools/releases/download/v" + nv + "/AdvSrvTools.dll", location);

                Log.Info("Updated Advanced Server Tools. Please restart your server to apply the update.");
                running = false;
                return;
            }
        }