public static bool TryParse(string rawstring, out PSO2Version result)
 {
     string[] spplitted = null;
     if (rawstring.IndexOf(underline[0]) > -1)
     {
         spplitted = rawstring.Split(underline, StringSplitOptions.RemoveEmptyEntries);
     }
     if (spplitted != null && spplitted.Length == 3)
     {
         if (spplitted.Length == 3)
         {
             result = new PSO2Version(rawstring, spplitted[0], spplitted[2]);
             return(true);
         }
         else if (spplitted.Length == 4)
         {
             result = new PSO2Version(rawstring, spplitted[0], spplitted[2], spplitted[3]);
             return(true);
         }
         else
         {
             result = null;
             return(false);
         }
     }
     else
     {
         result = null;
         return(false);
     }
 }
 public bool IsEqual(PSO2Version version)
 {
     if (this.MajorVersion == version.MajorVersion && this.ReleaseCandidateVersion == version.ReleaseCandidateVersion)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 /// <summary>
 /// Compare two version. 0 if equal, 1 if this version is higher than compared version, -1 if this version is lower than compared version.
 /// </summary>
 /// <param name="pso2ver">PSO2Version. The version to be compared.</param>
 /// <returns>int. 0 if equal, 1 if this version is higher than compared version, -1 if this version is lower than compared version.</returns>
 public int CompareTo(PSO2Version pso2ver)
 {
     if (this.MajorVersion < pso2ver.MajorVersion)
     {
         return(-1);
     }
     else if (this.MajorVersion > pso2ver.MajorVersion)
     {
         return(1);
     }
     else
     {
         if (this.ReleaseCandidateVersion < pso2ver.ReleaseCandidateVersion)
         {
             return(-1);
         }
         else if (this.ReleaseCandidateVersion > pso2ver.ReleaseCandidateVersion)
         {
             return(1);
         }
         else
         {
             if (this.BuildVersion < pso2ver.BuildVersion)
             {
                 return(-1);
             }
             else if (this.BuildVersion > pso2ver.BuildVersion)
             {
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
     }
 }
Beispiel #4
0
        private void BWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Infinite));

            WorkerParams wp       = e.Argument as WorkerParams;
            string       pso2Path = wp.PSO2Path;

            // Check if there is any prepatch files
            if (!wp.IgnorePrepatch)
            {
                string prepatchFolderData = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName, "data");
                if (!DirectoryHelper.IsFolderEmpty(prepatchFolderData))
                {
                    // Ignore prepatch files if it's older than the current client version
                    PSO2Version currentVersion  = PSO2Version.Parse(MySettings.PSO2Version);
                    PSO2Version prepatchVersion = PSO2Version.Parse(MySettings.PSO2PrecedeVersion.Version);
                    if (prepatchVersion.CompareTo(currentVersion) > 0)
                    {
                        this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_FoundValidPrepatch", "Found prepatch files which are ready to be used.");
                        ValidPrepatchPromptEventArgs myEventArgs = new ValidPrepatchPromptEventArgs();
                        this.OnValidPrepatchPrompt(myEventArgs);
                        if (myEventArgs.Use)
                        {
                            string[] filenames = Directory.GetFiles(prepatchFolderData, "*", SearchOption.AllDirectories);
                            this.CurrentStep   = LanguageManager.GetMessageText("PSO2Updater_MovingPrepatchFiles", "Applying prepatch files.");
                            this.ProgressTotal = filenames.Length;
                            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent));
                            string str = null, maindatafolder = Path.Combine(pso2Path, "data"), targetfile = null;
                            for (int i = 0; i < filenames.Length; i++)
                            {
                                str        = filenames[i];
                                targetfile = maindatafolder + str.Remove(0, prepatchFolderData.Length);
                                File.Delete(targetfile);
                                File.Move(str, targetfile);
                                this.ProgressCurrent = i + 1;
                            }

                            // Check if it's empty again to remove it
                            if (DirectoryHelper.IsFolderEmpty(prepatchFolderData))
                            {
                                string prepatchfolder = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName);
                                try
                                {
                                    Directory.Delete(prepatchfolder, true);
                                }
                                catch { }
                            }
                        }
                    }
                    else
                    {
                        this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_FoundInvalidPrepatch", "Found out-dated prepatch files which will be ignored. These files shouldn't be used and should be deleted.");
                        InvalidPrepatchPromptEventArgs myEventArgs = new InvalidPrepatchPromptEventArgs();
                        this.OnInvalidPrepatchPrompt(myEventArgs);
                        if (myEventArgs.Delete)
                        {
                            this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_DeletingInvalidPrepatch", "Deleting out-dated prepatch files.");
                            string prepatchfolder = Path.Combine(pso2Path, PrepatchManager.PrepatchManager.PrepatchFolderName);
                            try
                            {
                                Directory.Delete(prepatchfolder, true);
                            }
                            catch { }
                        }
                    }
                }
            }

            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Infinite));

            var patchinfo = this.CheckForUpdates();

            if (this.GetFilesList(patchinfo))
            {
                System.Collections.Concurrent.ConcurrentDictionary <string, PSO2File> myPSO2filesList = ParseFilelist(this.myFileList, patchinfo);
                if (!myPSO2filesList.IsEmpty)
                {
                    this.ProgressTotal = myPSO2filesList.Count;
                    this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent, new Forms.MyMainMenuCode.CircleProgressBarProperties(true)));
                    string verstring = wp.NewVersionString;
                    if (string.IsNullOrWhiteSpace(verstring))
                    {
                        verstring = this.myWebClient.DownloadString(Leayal.UriHelper.URLConcat(patchinfo.PatchURL, "version.ver"));
                    }
                    if (!string.IsNullOrWhiteSpace(verstring))
                    {
                        verstring = verstring.Trim();
                    }
                    anothersmallthreadpool                  = new AnotherSmallThreadPool(pso2Path, myPSO2filesList);
                    anothersmallthreadpool.StepChanged     += Anothersmallthreadpool_StepChanged;
                    anothersmallthreadpool.ProgressChanged += Anothersmallthreadpool_ProgressChanged;
                    anothersmallthreadpool.KaboomFinished  += Anothersmallthreadpool_KaboomFinished;

                    this.CurrentStep = LanguageManager.GetMessageText("PSO2Updater_BeginFileCheckAndDownload", "Begin the file check and download...");

                    anothersmallthreadpool.StartWork(new WorkerParams(pso2Path, verstring, wp.Installation, wp.IgnorePrepatch));
                    e.Result = null;
                }
                else
                {
                    e.Result = new PSO2UpdateResult(UpdateResult.Failed);
                }
            }
            else
            {
                e.Result = new PSO2UpdateResult(UpdateResult.Unknown);
                throw new PSO2UpdateException(LanguageManager.GetMessageText("PSO2UpdateManager_GetPatchListFailed", "Failed to get PSO2's file list."));
            }
        }