Ejemplo n.º 1
0
        public static async Task <XmlData> ReadAsync(string url)
        {
            XDocument doc = null;

            if (StreamHelper.IsWebUrl(url))
            {
                using var response = await StreamHelper.GetWebResponseAsync(url).ConfigureAwait(false);

                using var stream = response.GetResponseStream();

#if NETCOREAPP
                doc = await XDocument.LoadAsync(stream, LoadOptions.None, default).ConfigureAwait(false);
#else
                doc = XDocument.Load(stream, LoadOptions.None);
#endif
            }
            else
            {
                using var stream = StreamHelper.OpenAsyncRead(url);
#if NETCOREAPP
                doc = await XDocument.LoadAsync(stream, LoadOptions.None, default).ConfigureAwait(false);
#else
                doc = XDocument.Load(stream, LoadOptions.None);
#endif
            }

            return(ReadDoc(doc));
        }
Ejemplo n.º 2
0
        internal static async Task <InstallResult> InstallAsync(string url, IProgress <ProgressData> progress, bool createShortcuts)
        {
            InstallResult ret = new InstallResult {
                Success = true
            };

            if (Debugger.IsAttached)
            {
                return(ret);
            }

#if DEBUG
            return(ret);
#endif

            try
            {
                //Read the package
                progress?.Report(new ProgressData("Reading package"));
                XmlData serverData = await XmlData.ReadAsync(url).ConfigureAwait(false);

                ret.Id      = serverData.Id;
                ret.Version = serverData.Version;

                //If installed, check installed version
                try
                {
                    var localVersion = GetInstalledVersion(ret.Id);
                    if (localVersion >= serverData.Version)
                    {
                        return(ret);
                    }
                }
                catch { }

                //Install!
                progress?.Report(new ProgressData($"Preparing to install v{serverData.Version}"));

                //Unzip from the web
                string status = $"Installing v{serverData.Version}";
                string zipSrc = Path2.DepoPackage(serverData);
                if (StreamHelper.IsWebUrl(zipSrc))
                {
                    using var response = await StreamHelper.GetWebResponseAsync(zipSrc).ConfigureAwait(false);

                    using var source = response.GetResponseStream();
                    await UnzipPackage(source, Path2.InstalledDirectory(serverData.Id), status, progress).ConfigureAwait(false);
                }
                else
                {
                    using var source = StreamHelper.OpenAsyncRead(zipSrc);
                    await UnzipPackage(source, Path2.InstalledDirectory(serverData.Id), status, progress).ConfigureAwait(false);
                }



                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    RegistryEntries.RegisterUninstallInfo(serverData);

                    //Create desktop shortcut
                    string shortcutFile = Path2.DesktopLinkPath(serverData.Name);
                    if (createShortcuts || File.Exists(shortcutFile))
                    {
                        Shortcut.Create(shortcutFile, Path2.InstalledExe(serverData));
                    }
                }
                else
                {
                    Process.Start("chmod", $"+x \"{Path2.InstalledExe(serverData)}\"");
                }

                //Success
                serverData.Save(Path2.LocalManifest(serverData.Id));
                progress?.Report(new ProgressData("Done", 100, true));
            }
            catch (Exception ex)
            {
                ret.Success = false;
                ret.Error   = ex;
            }

            return(ret);
        }