示例#1
0
        private void cmdNext_Click(object sender, EventArgs e)
        {
            string text = null;
            string str  = null;
            int    num  = 0;

            if (!this.optDailyUpload.Checked)
            {
                text = this.txtDirect.Text;
                str  = string.Concat(Path.GetFileNameWithoutExtension(text), ".ipa");
            }
            else
            {
                num = URLInstall.DailyUpload(this.txtDailyUpload.Text, ref text, ref str);
            }
            if (num >= 0)
            {
                Common.Download(new DownloadProgress(), text, str);
                base.Close();
            }
            else
            {
                Interaction.MsgBox(string.Concat("Cannot download file! Is your link correct? ", num.ToString()), MsgBoxStyle.OkOnly, null);
            }
        }
        private async void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            int num;
            int num1;

            object[]         objArray;
            DownloadProgress downloadProgress;

            DownloadProgress.DownloadCompleteSafe downloadCompleteSafe;
            MsgBoxResult    msgBoxResult;
            object          obj;
            int             num2;
            HttpWebResponse response;
            long            num3 = 0L;

            DownloadProgress.DownloadCompleteSafe downloadCompleteSafe1;
            if (this.downloadLink.IndexOf("dailyuploads.net") >= 0)
            {
                num2 = URLInstall.DailyUpload(this.downloadLink, ref this.downloadLink, ref this.storeFile);
                if (num2 < 0)
                {
                    msgBoxResult          = Interaction.MsgBox(string.Concat("Cannot download file! Is your link correct? ", num2.ToString()), MsgBoxStyle.OkOnly, null);
                    downloadCompleteSafe1 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
                    try
                    {
                        downloadProgress     = this;
                        downloadCompleteSafe = downloadCompleteSafe1;
                        objArray             = new object[] { true };
                        obj = downloadProgress.Invoke(downloadCompleteSafe, objArray);
                    }
                    catch (Exception exception)
                    {
                        ProjectData.SetProjectError(exception);
                        ProjectData.ClearProjectError();
                    }
                    num1 = -2;
                    num  = num1;
                    return;
                }
            }
            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.downloadLink);
                response = (HttpWebResponse)httpWebRequest.GetResponse();
            }
            catch (Exception exception2)
            {
                ProjectData.SetProjectError(exception2);
                MessageBox.Show("An error occurred while downloading file. Possibe causes:\r\n1) File doesn't exist\r\n2) Remote server error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                DownloadProgress.DownloadCompleteSafe downloadCompleteSafe2 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
                try
                {
                    DownloadProgress downloadProgress1 = this;
                    DownloadProgress.DownloadCompleteSafe downloadCompleteSafe3 = downloadCompleteSafe2;
                    object[] objArray1 = new object[] { true };
                    downloadProgress1.Invoke(downloadCompleteSafe3, objArray1);
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    ProjectData.ClearProjectError();
                }
                ProjectData.ClearProjectError();
                num1 = -2;
                num  = num1;
                return;
            }
            long contentLength = response.ContentLength;

            DownloadProgress.ChangeTextsSafe changeTextsSafe = new DownloadProgress.ChangeTextsSafe(this.ChangeTexts);
            try
            {
                DownloadProgress downloadProgress2 = this;
                DownloadProgress.ChangeTextsSafe changeTextsSafe1 = changeTextsSafe;
                object[] objArray2 = new object[] { contentLength, 0, 0, 0 };
                downloadProgress2.Invoke(changeTextsSafe1, objArray2);
            }
            catch (Exception exception3)
            {
                ProjectData.SetProjectError(exception3);
                ProjectData.ClearProjectError();
            }
            FileStream fileStream          = new FileStream(this.localFile, FileMode.Create);
            Stopwatch  stopwatch           = new Stopwatch();
            double     elapsedMilliseconds = -1;
            int        num4 = 0;

            while (true)
            {
                if (!this.BackgroundWorker1.CancellationPending)
                {
                    stopwatch.Start();
                    byte[] numArray = new byte[4096];
                    int    num5     = response.GetResponseStream().Read(numArray, 0, 4096);
                    num3 = checked (num3 + (long)num5);
                    long num6 = checked ((long)Math.Round(Math.Round((double)(checked (num3 * (long)100)) / (double)contentLength)));
                    try
                    {
                        DownloadProgress downloadProgress3 = this;
                        DownloadProgress.ChangeTextsSafe changeTextsSafe2 = changeTextsSafe;
                        object[] objArray3 = new object[] { contentLength, num3, num6, elapsedMilliseconds };
                        downloadProgress3.Invoke(changeTextsSafe2, objArray3);
                    }
                    catch (Exception exception5)
                    {
                        ProjectData.SetProjectError(exception5);
                        response.GetResponseStream().Close();
                        fileStream.Close();
                        try
                        {
                            File.Delete(this.localFile);
                            DownloadProgress.DownloadCompleteSafe downloadCompleteSafe4 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
                            DownloadProgress downloadProgress4 = this;
                            DownloadProgress.DownloadCompleteSafe downloadCompleteSafe5 = downloadCompleteSafe4;
                            object[] objArray4 = new object[] { true };
                            downloadProgress4.Invoke(downloadCompleteSafe5, objArray4);
                        }
                        catch (Exception exception4)
                        {
                            ProjectData.SetProjectError(exception4);
                            ProjectData.ClearProjectError();
                        }
                        ProjectData.ClearProjectError();
                        num1 = -2;
                        num  = num1;
                        return;
                    }
                    if (num5 != 0)
                    {
                        fileStream.Write(numArray, 0, num5);
                        stopwatch.Stop();
                        num4 = checked (num4 + 1);
                        if (num4 >= 100)
                        {
                            elapsedMilliseconds = 409600 / ((double)stopwatch.ElapsedMilliseconds / 1000);
                            stopwatch.Reset();
                            num4 = 0;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            response.GetResponseStream().Close();
            fileStream.Close();
            if (!this.BackgroundWorker1.CancellationPending)
            {
                if (this.storeFile.EndsWith(".deb"))
                {
                    try
                    {
                        Directory.CreateDirectory(AppConst.m_localTmp);
                    }
                    catch (Exception exception6)
                    {
                        ProjectData.SetProjectError(exception6);
                        ProjectData.ClearProjectError();
                    }
                    try
                    {
                        File.Delete(string.Concat(AppConst.m_localTmp, "/data.tar"));
                    }
                    catch (Exception exception7)
                    {
                        ProjectData.SetProjectError(exception7);
                        ProjectData.ClearProjectError();
                    }
                    try
                    {
                        Common.DeleteFilesFromFolder(string.Concat(AppConst.m_localTmp, "/data"));
                    }
                    catch (Exception exception8)
                    {
                        ProjectData.SetProjectError(exception8);
                        ProjectData.ClearProjectError();
                    }
                    DownloadProgress.ChangeStatusSafe changeStatusSafe = new DownloadProgress.ChangeStatusSafe(this.ChangeStatus);
                    try
                    {
                        DownloadProgress downloadProgress5 = this;
                        DownloadProgress.ChangeStatusSafe changeStatusSafe1 = changeStatusSafe;
                        object[] objArray5 = new object[] { "Please wait for processing download file..." };
                        downloadProgress5.Invoke(changeStatusSafe1, objArray5);
                    }
                    catch (Exception exception9)
                    {
                        ProjectData.SetProjectError(exception9);
                        ProjectData.ClearProjectError();
                    }
                    Application.DoEvents();
                    string   str       = string.Concat(AppConst.m_rootPath, "\\7zip\\7z.exe");
                    string[] mLocalTmp = new string[] { "e \"", this.localFile, "\" -o\"", AppConst.m_localTmp, "\"" };
                    string   str1      = await Common.RunExe(str, string.Concat(mLocalTmp), true);

                    string   str2      = str1;
                    string   str3      = string.Concat(AppConst.m_rootPath, "\\7zip\\7z.exe");
                    string[] strArrays = new string[] { "x \"", AppConst.m_localTmp, "\\data.tar\" -o\"", AppConst.m_localTmp, "\\data\\\" -r -aoa" };
                    str1 = await Common.RunExe(str3, string.Concat(strArrays), true);

                    str2 = str1;
                    Directory.Move(string.Concat(AppConst.m_localTmp, "\\data\\Applications"), string.Concat(AppConst.m_localTmp, "\\data\\Payload"));
                    string   str4       = string.Concat(AppConst.m_rootPath, "\\7zip\\7z.exe");
                    string[] mLocalTmp1 = new string[] { "a -tzip \"", this.localFile, ".zip\" \"", AppConst.m_localTmp, "\\data\\*\"" };
                    str1 = await Common.RunExe(str4, string.Concat(mLocalTmp1), false);

                    str2           = str1;
                    this.storeFile = string.Concat(this.storeFile, ".ipa");
                    try
                    {
                        File.Delete(this.localFile);
                    }
                    catch (Exception exception10)
                    {
                        ProjectData.SetProjectError(exception10);
                        ProjectData.ClearProjectError();
                    }
                    try
                    {
                        File.Move(string.Concat(this.localFile, ".zip"), this.localFile);
                    }
                    catch (Exception exception11)
                    {
                        ProjectData.SetProjectError(exception11);
                        Interaction.MsgBox(exception11.Message, MsgBoxStyle.OkOnly, null);
                        ProjectData.ClearProjectError();
                    }
                }
                DownloadProgress.DownloadCompleteSafe downloadCompleteSafe6 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
                try
                {
                    DownloadProgress downloadProgress6 = this;
                    DownloadProgress.DownloadCompleteSafe downloadCompleteSafe7 = downloadCompleteSafe6;
                    object[] objArray6 = new object[] { false };
                    downloadProgress6.Invoke(downloadCompleteSafe7, objArray6);
                }
                catch (Exception exception12)
                {
                    ProjectData.SetProjectError(exception12);
                    ProjectData.ClearProjectError();
                }
            }
            else
            {
                File.Delete(this.localFile);
                DownloadProgress.DownloadCompleteSafe downloadCompleteSafe8 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
                try
                {
                    DownloadProgress downloadProgress7 = this;
                    DownloadProgress.DownloadCompleteSafe downloadCompleteSafe9 = downloadCompleteSafe8;
                    object[] objArray7 = new object[] { true };
                    downloadProgress7.Invoke(downloadCompleteSafe9, objArray7);
                }
                catch (Exception exception13)
                {
                    ProjectData.SetProjectError(exception13);
                    ProjectData.ClearProjectError();
                }
            }
            num1 = -2;
            num  = num1;
            return;

            msgBoxResult          = Interaction.MsgBox(string.Concat("Cannot download file! Is your link correct? ", num2.ToString()), MsgBoxStyle.OkOnly, null);
            downloadCompleteSafe1 = new DownloadProgress.DownloadCompleteSafe(this.DownloadComplete);
            try
            {
                downloadProgress     = this;
                downloadCompleteSafe = downloadCompleteSafe1;
                objArray             = new object[] { true };
                obj = downloadProgress.Invoke(downloadCompleteSafe, objArray);
            }
            catch (Exception exception)
            {
                ProjectData.SetProjectError(exception);
                ProjectData.ClearProjectError();
            }
            num1 = -2;
            num  = num1;
        }