Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SolutionDetails" /> class.
 /// </summary>
 /// <param name="dsd">The DSD.</param>
 /// <param name="helpText">The help text.</param>
 /// <param name="appName">Name of the application.</param>
 /// <param name="appRepoName">Name of the application repo.</param>
 /// <param name="version">The version.</param>
 /// <param name="aboutScreenOtherText">The about screen other text.</param>
 public SolutionDetails(LicenseCallback dsd, string helpText = null, string appName = null,
     string appRepoName = null, Version version = null, string aboutScreenOtherText = null)
 {
     AppRepo = appRepoName;
     HelpText = helpText;
     this.AppName = appName;
     AboutScreenOtherText = aboutScreenOtherText;
     Ld = new LicensingDetails() {Callback = dsd, CurrentVersion = version};
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SolutionDetails" /> class.
 /// </summary>
 /// <param name="dsd">The DSD.</param>
 /// <param name="helpText">The help text.</param>
 /// <param name="appName">Name of the application.</param>
 /// <param name="appRepoName">Name of the application repo.</param>
 /// <param name="version">The version.</param>
 /// <param name="aboutScreenOtherText">The about screen other text.</param>
 public SolutionDetails(LicenseCallback dsd, string helpText = null, string appName = null,
                        string appRepoName = null, Version version = null, string aboutScreenOtherText = null)
 {
     AppRepo              = appRepoName;
     HelpText             = helpText;
     this.AppName         = appName;
     AboutScreenOtherText = aboutScreenOtherText;
     Ld = new LicensingDetails()
     {
         Callback = dsd, CurrentVersion = version
     };
 }
Exemplo n.º 3
0
        private static async Task <LicensingDetails> GetUpdateDetails()
        {
            bool   error    = false;
            string errormsg = null;
            var    ld       = _sd.Ld;

            try
            {
                await _sd.Callback();
            }
            catch (Exception ex)
            {
                error    = true;
                errormsg = "Error while getting new version:" + ex;
            }

            if (ld?.OnlineVersion == null || error)
            {
                if (ld == null)
                {
                    ld = new LicensingDetails();
                }

                ld.Response        = LicensingDetails.LicenseResponse.Error;
                ld.ResponseMessage = errormsg ?? "Error while getting new version";
            }
            else
            {
                if (_sd.Ld.CurrentVersion >= ld.OnlineVersion)
                {
                    ld.Response        = LicensingDetails.LicenseResponse.UpToDate;
                    ld.ResponseMessage = "No update required, you already have an up to date version of " + _sd.AppName;
                }

                ld.ChangeLog       = ld.ChangeLog;
                ld.Response        = LicensingDetails.LicenseResponse.NewVersion;
                ld.ResponseMessage = "New update available.\r\n" + "Your version of " + _sd.AppName + ":" + _sd.Ld.CurrentVersion +
                                     "\nNewest version online:" +
                                     ld.OnlineVersion;
            }

            return(ld);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the git hub release details.
        /// </summary>
        /// <param name="ld">The ld.</param>
        /// <param name="appRepo">The application repo.</param>
        /// <returns></returns>
        public static async Task<LicensingDetails> GetGitHubReleaseDetails(LicensingDetails ld, string appRepo)
        {
            try
            {
                var det = NetExtras.DownloadWebPage($"https://github.com/andreigec/{appRepo}/releases/latest");
                if (det.IsFaulted)
                    return null;
                var htmlText = await det;

                ld.OnlineVersion = GetVersion(htmlText);
                ld.FileLocation = GetDownloadPath(htmlText);
                ld.ChangeLog = GetChangeLog(htmlText);

                return ld;
            }
            catch
            {
            }
            return null;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the git hub release details.
        /// </summary>
        /// <param name="ld">The ld.</param>
        /// <param name="appRepo">The application repo.</param>
        /// <returns></returns>
        public static async Task <LicensingDetails> GetGitHubReleaseDetails(LicensingDetails ld, string appRepo)
        {
            try
            {
                var det = NetExtras.DownloadWebPage($"https://github.com/andreigec/{appRepo}/releases/latest");
                if (det.IsFaulted)
                {
                    return(null);
                }
                var htmlText = await det;

                ld.OnlineVersion = GetVersion(htmlText);
                ld.FileLocation  = GetDownloadPath(htmlText);
                ld.ChangeLog     = GetChangeLog(htmlText);

                return(ld);
            }
            catch
            {
            }
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the application.
        /// </summary>
        /// <param name="dsd">The DSD.</param>
        private static void UpdateApplication(LicensingDetails dsd)
        {
            string folder;
            string localfile;
            //we need the exe file for later execution
            var    exefile = "";
            string exefolder;

            try
            {
                //0: reset current directory in case it was changed
                Directory.SetCurrentDirectory(Application.StartupPath);
                //1: Get the online files
                folder = _sd.AppName + "v" + DateTime.Now.Ticks;
                Directory.CreateDirectory(folder);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while creating the temporary folder\n:" + ex);
                return;
            }

            try
            {
                var client = new WebClient();
                localfile = dsd.FileLocation.Substring(dsd.FileLocation.LastIndexOf('/') + 1);
                client.DownloadFile(dsd.FileLocation, localfile);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while downloading new files\n:" + ex);
                return;
            }

            try
            {
                var          myname = AppDomain.CurrentDomain.FriendlyName;
                const string vshost = ".vshost.";
                //remove .vshost for testing
                if (myname.Contains(vshost))
                {
                    myname = myname.Replace(vshost, ".");
                }

                //2.1 unpack
                ZipExtras.ExtractZipFile(localfile, folder);

                //2.2 find exe
                foreach (var f in DirectoryExtras.GetFilesRecursive(folder))
                {
                    if (f.Contains(".exe"))
                    {
                        exefile = f;
                    }

                    if (f.EndsWith(myname))
                    {
                        break;
                    }
                }

                const string br = "\\";
                exefolder = "";
                //ignore everything above this dir
                while (exefile.Length > 0)
                {
                    var c = StringExtras.ContainsSubStringCount(exefile, br);
                    if (c > 0)
                    {
                        var s = exefile.Substring(0, exefile.IndexOf(br, StringComparison.Ordinal));
                        exefolder += s + br;
                        exefile    = exefile.Substring(exefile.IndexOf(br, StringComparison.Ordinal) + 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while unzipping new files\n:" + ex);
                return;
            }

            //move folder/* to the local dir
            //delete the zip file
            //delete folder remnants
            //start the exefile we found before

            var operations = "move /Y \"" + exefolder + "\"\\* . " +
                             "& del /Q \"" + localfile + "\" " +
                             "& rmdir /Q /S \"" + folder + "\" " +
                             "& start \"\" \"" + exefile + "\" ";

            RunCommands(operations);

            //4: Kill process
            Application.Exit();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Updates the application.
        /// </summary>
        /// <param name="dsd">The DSD.</param>
        private static void UpdateApplication(LicensingDetails dsd)
        {
            string folder;
            string localfile;
            //we need the exe file for later execution
            var exefile = "";
            string exefolder;

            try
            {
                //0: reset current directory in case it was changed
                Directory.SetCurrentDirectory(Application.StartupPath);
                //1: Get the online files
                folder = _sd.AppName + "v" + DateTime.Now.Ticks;
                Directory.CreateDirectory(folder);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while creating the temporary folder\n:" + ex);
                return;
            }

            try
            {
                var client = new WebClient();
                localfile = dsd.FileLocation.Substring(dsd.FileLocation.LastIndexOf('/') + 1);
                client.DownloadFile(dsd.FileLocation, localfile);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while downloading new files\n:" + ex);
                return;
            }

            try
            {
                var myname = AppDomain.CurrentDomain.FriendlyName;
                const string vshost = ".vshost.";
                //remove .vshost for testing
                if (myname.Contains(vshost))
                    myname = myname.Replace(vshost, ".");

                //2.1 unpack
                ZipExtras.ExtractZipFile(localfile, folder);

                //2.2 find exe
                foreach (var f in DirectoryExtras.GetFilesRecursive(folder))
                {
                    if (f.Contains(".exe"))
                        exefile = f;

                    if (f.EndsWith(myname))
                        break;
                }

                const string br = "\\";
                exefolder = "";
                //ignore everything above this dir
                while (exefile.Length > 0)
                {
                    var c = StringExtras.ContainsSubStringCount(exefile, br);
                    if (c > 0)
                    {
                        var s = exefile.Substring(0, exefile.IndexOf(br, StringComparison.Ordinal));
                        exefolder += s + br;
                        exefile = exefile.Substring(exefile.IndexOf(br, StringComparison.Ordinal) + 1);
                    }
                    else
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while unzipping new files\n:" + ex);
                return;
            }

            //move folder/* to the local dir
            //delete the zip file
            //delete folder remnants
            //start the exefile we found before

            var operations = "move /Y \"" + exefolder + "\"\\* . " +
                             "& del /Q \"" + localfile + "\" " +
                             "& rmdir /Q /S \"" + folder + "\" " +
                             "& start \"\" \"" + exefile + "\" ";

            RunCommands(operations);

            //4: Kill process			
            Application.Exit();
        }
Exemplo n.º 8
0
        private static async Task<LicensingDetails> GetUpdateDetails()
        {
            bool error = false;
            string errormsg = null;
            var ld = _sd.Ld;
            try
            {
                await _sd.Callback();
            }
            catch (Exception ex)
            {
                error = true;
                errormsg = "Error while getting new version:" + ex;
            }

            if (ld?.OnlineVersion == null || error)
            {
                if (ld == null)
                    ld = new LicensingDetails();

                ld.Response = LicensingDetails.LicenseResponse.Error;
                ld.ResponseMessage = errormsg ?? "Error while getting new version";
            }
            else
            {
                if (_sd.Ld.CurrentVersion >= ld.OnlineVersion)
                {
                    ld.Response = LicensingDetails.LicenseResponse.UpToDate;
                    ld.ResponseMessage = "No update required, you already have an up to date version of " + _sd.AppName;
                }

                ld.ChangeLog = ld.ChangeLog;
                ld.Response = LicensingDetails.LicenseResponse.NewVersion;
                ld.ResponseMessage = "New update available.\r\n" + "Your version of " + _sd.AppName + ":" + _sd.Ld.CurrentVersion +
                           "\nNewest version online:" +
                           ld.OnlineVersion;
            }

            return ld;
        }