Пример #1
0
 public PatchResult(Patch patch, PatchStatus result, string message = "", Exception ex = null)
 {
     PatchName = patch.Name;
     Result    = result;
     Message   = message;
     Exception = ex;
 }
Пример #2
0
 private void ButtonCheckForUpdates_Click(object sender, EventArgs e)
 {
     if ((this.m_PatchStatus != PatchStatus.Checking) && (this.m_PatchStatus != PatchStatus.Updating))
     {
         this.downloadProgressBar.Value = 0;
         this.m_aNeedsUpdate.Clear();
         using (WebClient client = new WebClient())
         {
             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
             client.DownloadStringCompleted      += delegate(object sdr, DownloadStringCompletedEventArgs ex) {
                 string[] textArray1 = new string[] { ex.Result.Contains(Environment.NewLine) ? Environment.NewLine : "\n" };
                 string[] separator  = new string[] { ex.Result.Contains(Environment.NewLine) ? Environment.NewLine : "\n" };
                 string[] strArray   = ex.Result.Split(separator, StringSplitOptions.None);
                 for (int i = 0; i < strArray.Length; i++)
                 {
                     char[]   chArray1  = new char[] { ' ' };
                     string[] strArray2 = strArray[i].Split(chArray1, 3);
                     this.m_aNeedsUpdate.Add(new PatchEntry(strArray2[0], (long)int.Parse(strArray2[1]), strArray2[2]));
                 }
                 this.CheckForUpdates();
             };
             try
             {
                 client.DownloadStringAsync(new Uri("https://ac.windia.me/patch_info"));
             }
             catch (WebException)
             {
                 MessageBox.Show("Error connecting to patch server.", "Patcher error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             }
             this.labelStatusText.Text = "Checking...";
             this.m_PatchStatus        = PatchStatus.Checking;
         }
     }
 }
Пример #3
0
 private void ButtonDownload_Click(object sender, EventArgs e)
 {
     if (((this.m_PatchStatus != PatchStatus.Checking) && (this.m_PatchStatus != PatchStatus.Updating)) && ((this.m_aNeedsUpdate.Count < 20) || (System.IO.File.Exists("Windia.exe") || (MessageBox.Show("This seems to be your first time using the patcher!\n*Please* make sure that this patcher file is located in an *empty* folder. This patcher will download the game files to the same folder it is being ran from!\n\nIf you're having issues, try to disable your antivirus software.\nIf you can't get the patcher to work, feel free to ask for help on forums or on our Discord server.\n\nDo you want to proceed?", "Windia Patcher", MessageBoxButtons.YesNo) != DialogResult.No))))
     {
         Process[] processesByName = Process.GetProcessesByName("Windia.dll");
         if ((processesByName.Length != 0) && (MessageBox.Show("Seems like Windia is running on your computer. Patching the game while it is running might not work.\n\nSelect Yes to close all Windia processes, or No to attempt patching regardless.", "Windia Patcher", MessageBoxButtons.YesNo) == DialogResult.Yes))
         {
             Process[] processArray2 = processesByName;
             for (int i = 0; i < processArray2.Length; i++)
             {
                 processArray2[i].Kill();
                 Thread.Sleep(0x3e8);
             }
         }
         this.m_PatchStatus = PatchStatus.Updating;
         new Thread(new ThreadStart(this.DownloadThread)).Start();
     }
 }
Пример #4
0
        private Brush GetBrushForStatus(PatchStatus status)
        {
            switch (status)
            {
            case PatchStatus.None:
                return(Brushes.Black);

            case PatchStatus.Error:
                return(Brushes.Red);

            case PatchStatus.Applied:
                return(Brushes.Green);

            case PatchStatus.Normal:
                return(Brushes.Blue);

            default:
                throw new ArgumentOutOfRangeException(nameof(status), status, null);
            }
        }
Пример #5
0
 private void CheckForUpdates()
 {
     this.m_aPendingPatch.Clear();
     foreach (PatchEntry entry in this.m_aNeedsUpdate)
     {
         if (entry.SizeInBytes != this.GetFileSize(entry.FileName))
         {
             this.m_aPendingPatch.Add(entry);
         }
     }
     if (this.m_aPendingPatch.Count == 0)
     {
         this.m_PatchStatus        = PatchStatus.Updated;
         this.labelStatusText.Text = "Files are updated.";
     }
     else
     {
         this.m_PatchStatus          = PatchStatus.Outdated;
         this.labelStatusText.Text   = "Files are outdated.";
         this.buttonDownload.Enabled = true;
     }
 }
Пример #6
0
 public PatchResult Result(PatchStatus status = PatchStatus.Success, string message = "", Exception ex = null) =>
 new PatchResult(this, status, message, ex);
Пример #7
0
    void StartGame()
    {
        statusText = "About to start game...";
        string filename = "";
        if (IsWindows())
            filename = GetExecutable();
        else if (IsMac())
            filename = GetMacApp();
        else
        {
            SetError("Unsupported platform!");
            return;
        }

        currentStatus = PatchStatus.startinggame;

        if (!System.IO.File.Exists(filename))
        {
            cannotFindGame = true;
            SetError("Could not find the application when trying to execute the game!");
            return;
        }
        System.Diagnostics.Process Proc = new System.Diagnostics.Process();
        Proc.StartInfo.FileName = filename;
        Proc.Start();

        Application.Quit();
    }
Пример #8
0
    IEnumerator Start()
    {
        statusText = "Starting updater...";
        currentStatus = PatchStatus.readingsettingsfile;

        Application.runInBackground = true;

        //Read settings
        Dictionary<string, string> settingsDict = ReadSettings();
        if (currentStatus == PatchStatus.failed) yield break;

        //Get latest version information
        yield return StartCoroutine(GetLatestVersion(settingsDict));
        if (currentStatus == PatchStatus.failed) yield break;

        Debug.Log("Start Got the settings and latest online version");

        if (NeedsToUpdate(settingsDict))
        {
            Debug.Log("Start We need to update!");

            //Download and Unzip latest game
            yield return StartCoroutine(DownloadGame(settingsDict));
            if (currentStatus == PatchStatus.failed) yield break;

            //Write new settings file
            WriteNewSettingsFile(settingsDict);

           /*
            if (IsMac())
            {
               // System.Diagnostics.Process Proc = new System.Diagnostics.Process();
               // Proc.StartInfo.FileName = "FixPermissions.app/Contents/MacOS/applet";
                //Proc.Start();

                SetError("The game has updated, please run the FixPermissions file once. After doing so you can launch the game!");
                yield break;
            }*/

            //Reload patcher to check for further updates OR start game.
            Application.LoadLevel(Application.loadedLevel);
            yield break; //dont run StartGame();
        }
        else
        {
            statusText = "Up to date!";
        }

        //Start the up2date game :)
        StartGame();
    }
Пример #9
0
 void SetError(string err)
 {
     Debug.LogError("SetError: " + err);
     currentStatus = PatchStatus.failed;
     errorMessage = err;
 }
Пример #10
0
    IEnumerator GetLatestVersion(Dictionary<string, string> settingsDict)
    {
        statusText = "Downloading latest version information...";
        currentStatus = PatchStatus.getlatestversioninfo;
        WWWForm form = new WWWForm();
        form.AddField("platform", "" + Application.platform);

        string curVersion = "0";
        if (settingsDict.ContainsKey("thisVersion")) curVersion = settingsDict["thisVersion"];
        form.AddField("clientsversion", "" + curVersion);
        form.AddField("buildTarget", "" + settingsDict["BuildTarget"]);

        WWW www = new WWW(settingsDict["universalPatchInfo"], form);

        while (!www.isDone)
        {
            currentProgressPercent = www.progress;
            yield return 0;
        }

        yield return www;
        if (www.error != null)
        {
            SetError("Couldn't connect to the patch server.");
            yield break;
        }
        else
        {
            Debug.Log("GetLatestVersion=" + www.text);
            string info = www.text;
            if (info.Substring(0, 1) != "1")
            {
                SetError("Unable to connect to update server.");
                yield break;
            }

            string[] infoArray = info.Substring(1).Split('#');
            if (infoArray.Length < 3)
            {
                SetError("Latest version information is wrong (" + infoArray.Length + " <- should >=3)");
                yield break;
            }

            settingsDict.Add("latestVersion", infoArray[0]);
            settingsDict.Add("patchVersion", infoArray[1]);
            settingsDict.Add("downloadlink", infoArray[2]);
            settingsDict.Add("disabledLink", infoArray[3]);

            if (settingsDict["disabledLink"].Length >= 4)
            {
                patchUpdateLink = settingsDict["disabledLink"];
                SetError("Couldn't update, please click the button below for more information.");
                yield break;
            }

        }
    }
Пример #11
0
    IEnumerator DownloadGame(Dictionary<string, string> settingsDict)
    {
        statusText = "Starting download...";
        currentStatus = PatchStatus.downloading;
        WWW www = new WWW(settingsDict["downloadlink"]);

        while (!www.isDone)
        {
            currentProgressPercent = www.progress;
            statusText = "Downloading patch " + settingsDict["thisVersion"] + " -> " + settingsDict["patchVersion"] + ": " + Mathf.Round(www.progress * 100) + "%"; //\nTime passed:" + Mathf.Round(Time.realtimeSinceStartup - downloadStarted) + " seconds - Remaining:" + Mathf.Ceil(remain) + " seconds";

            yield return 0;
        }
        if (www.error != null && www.error != "" || www.bytes.Length<=0)
        {
            SetError("Download failed for: "+www.url);
            yield break;
        }

        currentStatus = PatchStatus.unzipping;

        statusText = "Unzipping...";
        yield return 0;
        //Process the update: unzip, copy/patch/remove
        string tmpRoot = TMPFolder();
        string tmpFolder = tmpRoot + Application.platform + settingsDict["latestVersion"] + "/";
        if (!UnzipUpdate(www, tmpFolder))
        {
            DeleteDirectory(tmpRoot);
            yield break;
        }
        if (!ProcessUpdateData(tmpFolder))
        {
            DeleteDirectory(tmpRoot);
            yield break;
        }
        DeleteDirectory(tmpRoot);

        Debug.Log("Applied patch " + settingsDict["patchVersion"] + " on version " + settingsDict["thisVersion"] + " latest=" + settingsDict["latestVersion"]+" downloadLink="+settingsDict["downloadlink"]);
        settingsDict["thisVersion"] = settingsDict["patchVersion"];
    }
Пример #12
0
 public RerwiteHTMLResult(string htmlContent, PatchStatus en, PatchStatus item)
 {
     this.HTML         = htmlContent;
     this.EnglishPatch = en;
     this.ItemPatch    = item;
 }
Пример #13
0
 public RerwiteHTMLResult(string htmlContent, PatchStatus en) : this(htmlContent, en, PatchStatus.Unknown)
 {
 }
Пример #14
0
        public static RerwiteHTMLResult RerwiteHTML(string htmlContent, string StartString)
        {
            string      result1 = htmlContent;
            PatchStatus result2 = PatchStatus.Unknown;
            PatchStatus result3 = PatchStatus.Unknown;

            System.Text.StringBuilder TheStringBuilder = new System.Text.StringBuilder();
            bool StartedAr = false;

            StartString = StartString.ToLower();
            using (System.IO.StringReader TheStreamReader = new System.IO.StringReader(htmlContent))
            {
                //"PSO2 Patch Compatibility"
                string TheLine      = null;
                string TheLowerLine = null;
                while ((TheStreamReader.Peek() > 0))
                {
                    TheLine      = TheStreamReader.ReadLine();
                    TheLowerLine = TheLine.ToLower();
                    if ((TheLowerLine.IndexOf(StartString) > -1))
                    {
                        StartedAr = true;
                    }
                    if ((StartedAr == true))
                    {
                        TheStringBuilder.AppendLine(TheLine);
                    }
                    if ((TheLowerLine.IndexOf("english patch:") > -1))
                    {
                        if ((TheLowerLine.IndexOf("color=\"green\"") > -1))
                        {
                            result2 = PatchStatus.Compatible;
                        }
                        else if ((TheLowerLine.IndexOf("color=\"red\"") > -1))
                        {
                            result2 = PatchStatus.Incompatible;
                        }
                        else if ((TheLowerLine.IndexOf("color=\"d4a017\"") > -1))
                        {
                            result2 = PatchStatus.Unknown;
                        }
                    }
                    else if ((TheLowerLine.IndexOf(">") > -1) && (TheLowerLine.IndexOf("item") > -1) && (TheLowerLine.IndexOf(":") > -1))
                    {
                        if ((TheLowerLine.IndexOf("color=\"green\"") > -1))
                        {
                            result3 = PatchStatus.Compatible;
                        }
                        else if ((TheLowerLine.IndexOf("color=\"red\"") > -1))
                        {
                            result3 = PatchStatus.Incompatible;
                        }
                        else if ((TheLowerLine.IndexOf("color=\"d4a017\"") > -1))
                        {
                            result3 = PatchStatus.Unknown;
                        }
                    }
                }
            }
            string TheStringB = TheStringBuilder.ToString();

            if ((TheStringB.ToLower().IndexOf("</html>") > -1))
            {
                TheStringB = TheStringB.Remove(TheStringB.ToLower().IndexOf("</html>"), 7);
            }
            if (string.IsNullOrWhiteSpace(TheStringB))
            {
                result1 = string.Empty;
            }
            else
            {
                result1 = "<HTML><META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\"><META HTTP-EQUIV=\"Expires\" CONTENT=\"-1\"><BODY>" + TheStringB + "</BODY></HTML>";
            }
            return(new Classes.AIDA.RerwiteHTMLResult(result1, result2, result3));
        }
Пример #15
0
        //private static Task<bool> ConnectClient () {

        //}

        public static void StartPatchCheck(string dir)
        {
            Status = PatchStatus.Connecting;
            StatusChanged.Invoke(null, new EventArgs());
            downloadDirectory = dir;
            Directory.CreateDirectory(downloadDirectory);
            FileChecker.GetFilesDictionaryProgress += ProgressUpdateReceived;
            Task.Run(() => FileChecker.GetFilesDictionary(out allFilesDictionary, downloadDirectory));

            while (allFilesDictionary == null)
            {
            }
            while (client == null)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(16.66667));
                try {
                    client = new TcpClient(GlobalVariables.PATCHMANAGER_IP, GlobalVariables.PATCHMANAGER_PORT);
                }
                catch {
                }
            }



            SendFileDictionaryToServer();
            MissingFiles = null;
            Completed    = false;

            bool waitingForFile = false;

            Status = PatchStatus.Downloading;
            StatusChanged.Invoke(null, new EventArgs());

            while (!Completed)
            {
                if (MessageFormatter.Connected(client))
                {
                    if (MissingFiles == null)
                    {
                        while (client.GetStream().DataAvailable)
                        {
                            string jsonList = MessageFormatter.ReadStreamOnce(client.GetStream());
                            MissingFiles = JsonConvert.DeserializeObject <FileTransferModel>(jsonList);
                            MissingFilesUpdated.Invoke(null, new EventArgs());
                            if (MissingFiles.Files.Count == 0)
                            {
                                DownloadComplete.Invoke(null, new EventArgs());
                                Status = PatchStatus.Done;
                                StatusChanged.Invoke(null, new EventArgs());
                                Completed = true;
                            }
                        }
                    }
                    //Start requesting missing files from server
                    else if (MissingFiles.Files.Count > 0)
                    {
                        if (!waitingForFile)
                        {
                            byte [] fileRequestData = MessageFormatter.MessageBytes(MissingFiles.Files [0].FilePath);
                            client.GetStream().Write(fileRequestData, 0, fileRequestData.Length);
                            waitingForFile = true;
                        }
                        else
                        {
                            while (client.GetStream().DataAvailable)
                            {
                                MessageFormatter.ReadFile(client, MissingFiles.Files [0].FilePath, downloadDirectory);
                                MissingFiles.RemainingSize -= MissingFiles.Files [0].Size;
                                MissingFilesUpdated.Invoke(null, new EventArgs());
                                MissingFiles.Files.RemoveAt(0);
                                waitingForFile = false;
                            }
                        }
                        if (MissingFiles.Files.Count == 0)
                        {
                            waitingForFile = false;
                            DownloadComplete.Invoke(null, new EventArgs());
                            Status = PatchStatus.Done;
                            StatusChanged.Invoke(null, new EventArgs());
                            Completed = true;
                        }
                    }
                }
            }
            client.Dispose();
        }