コード例 #1
0
 public static void DownloadFileByDirect(string save_filename, string download_url, InputFormRef.AutoPleaseWait pleaseWait)
 {
     U.HttpDownload(save_filename, download_url, Path.GetDirectoryName(download_url), pleaseWait);
 }
コード例 #2
0
        public static void HttpDownload(string savefilename, string url, string referer = "", InputFormRef.AutoPleaseWait pleaseWait = null, System.Net.CookieContainer cookie = null)
        {
            HttpWebRequest request = HttpMakeRequest(url, referer, cookie);

            WebResponse rsp = request.GetResponse();

            using (Stream output = File.OpenWrite(savefilename))
                using (Stream input = rsp.GetResponseStream())
                {
                    byte[] buffer        = new byte[1024 * 8];
                    int    totalSize     = (int)rsp.ContentLength;
                    int    readTotalSize = 0;
                    int    bytesRead;
                    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        output.Write(buffer, 0, bytesRead);

                        if (pleaseWait != null)
                        {
                            readTotalSize += bytesRead;
                            if (totalSize == -1)
                            {
                                pleaseWait.DoEvents("Download: " + readTotalSize + "/" + "???");
                            }
                            else
                            {
                                pleaseWait.DoEvents("Download: " + readTotalSize + "/" + totalSize);
                            }
                        }
                    }
                }

            rsp.Close();

            if (cookie != null)
            {
                System.Net.CookieCollection cookies = request.CookieContainer.GetCookies(request.RequestUri);
                cookie.Add(cookies);
            }
        }
コード例 #3
0
        private void InstallButton_Click(object sender, EventArgs e)
        {
            if (InputFormRef.IsPleaseWaitDialog(this))
            {//2重割り込み禁止
                return;
            }

            string InstallDir = PathTextBox.Text;

            if (!Directory.Exists(InstallDir))
            {
                U.mkdir(InstallDir);
            }

            //少し時間がかかるので、しばらくお待ちください表示.
            using (InputFormRef.AutoPleaseWait pleaseWait = new InputFormRef.AutoPleaseWait(this))
            {
                pleaseWait.DoEvents("Check Lastest Version...");

                string url;
                string r = CheckUpdateURLByGitHub(out url);
                if (r != "")
                {
                    R.ShowStopError(r);
                    return;
                }
                this.URL = url;

                string update7z = Path.GetTempFileName();

                pleaseWait.DoEvents("Download...");
                //ダウンロード
                try
                {
                    U.DownloadFileByDirect(update7z, this.URL, pleaseWait);
                }
                catch (Exception ee)
                {
                    BrokenDownload(ee);
                    return;
                }
                if (!File.Exists(update7z))
                {
                    BrokenDownload("There are no files to download.");
                    return;
                }
                if (U.GetFileSize(update7z) < 2 * 1024 * 1024)
                {
                    BrokenDownload("Downloaded file is too small.");
                    return;
                }

                pleaseWait.DoEvents("Extract...");

                //解凍
                try
                {
                    string _update = InstallDir;
                    U.mkdir(_update);
                    r = ArchSevenZip.Extract(update7z, _update);
                    if (r != "")
                    {
                        BrokenDownload("The downloaded file could not be decompressed." + "\r\n" + r);
                        return;
                    }
                }
                catch (Exception ee)
                {
                    BrokenDownload(ee);
                    return;
                }

                string updateNewVersionFilename = Path.Combine(InstallDir, "FEBuilderGBA.exe");
                if (!File.Exists(updateNewVersionFilename))
                {
                    BrokenDownload("There was no executable file when unzipping the downloaded file.");
                    return;
                }
                if (U.GetFileSize(updateNewVersionFilename) < 2 * 1024 * 1024)
                {
                    BrokenDownload("The executable file was too small when unzipping the downloaded file.");
                    return;
                }

                pleaseWait.DoEvents("GO!");
            }
            R.ShowOK("Installation is completed!!\r\nStart FEBuilderGBA.");

            try
            {
                string updateNewVersionFilename = Path.Combine(InstallDir, "FEBuilderGBA.exe");

                Process p = new Process();
                p.StartInfo.FileName = updateNewVersionFilename;
                //p.StartInfo.UseShellExecute = false;
                p.Start();
            }
            catch (Exception ee)
            {
                BrokenDownload(ee);
                return;
            }

            this.Close();
        }