Ejemplo n.º 1
0
        void DownloadFile(string url, string filename)
        {
            try {
                //Setup webrequest
                DateTime startTime = DateTime.UtcNow;
                var      response  = HTTP.Request("GET", url);
                int      max       = (int)(response.ContentLength / 0x1000);

                //Read response in chunks of 0x1000 bytes
                string filepath = string.Format("{0}/{1}", Directory.GetCurrentDirectory(), filename);
                using (Stream responseStream = response.GetResponseStream()) {
                    using (Stream fileStream = File.OpenWrite(filepath)) {
                        byte[] buffer    = new byte[0x1000];
                        int    bytesRead = 0;
                        do
                        {
                            bytesRead = responseStream.Read(buffer, 0, 0x1000);
                            fileStream.Write(buffer, 0, bytesRead);
                            if ((DateTime.UtcNow - startTime).TotalMinutes > 5)
                            {
                                throw new ApplicationException("Download timed out");
                            }
                            ThreadSafe(() => {
                                progBar.Maximum = (max < 0x1000 ? 1 : max);
                                progBar.Step    = 1;
                                progBar.PerformStep();
                            });
                        } while (bytesRead > 0);
                    }
                }
                response.Close();
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 2
0
        string GetMetadataUrl(string tid, string ver)
        {
            string url      = string.Format("{0}/t/a/{1}/{2}", Properties.Resources.CDNUrl, tid, ver);
            var    response = HTTP.Request("HEAD", url);

            return(string.Format("{0}/c/a/{1}", Properties.Resources.CDNUrl, response.Headers.Get("X-Nintendo-Content-ID")));
        }
Ejemplo n.º 3
0
        string GetMetadataUrl(string tid, string ver)
        {
            string url = string.Format("{0}/t/a/{1}/{2}", Properties.Resources.CDNUrl, tid, ver);
            string ret = "";

            try {
                var response = HTTP.Request("HEAD", url);
                ret = string.Format("{0}/c/a/{1}", Properties.Resources.CDNUrl, response.Headers.Get("X-Nintendo-Content-ID"));
            }
            catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }
            return(ret);
        }
Ejemplo n.º 4
0
        string GetMetadataUrl(string tid, string ver)
        {
            StatusWrite("Getting meta NcaId..");
            string url = string.Format("{0}/t/a/{1}/{2}", Settings.GetCdnUrl(), tid, ver);
            string ret = "";

            try {
                var response = HTTP.Request("HEAD", url);
                ret = string.Format("{0}/c/a/{1}", Settings.GetCdnUrl(), response.Headers.Get("X-Nintendo-Content-ID"));
                response.Close();
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }
            return(ret);
        }
Ejemplo n.º 5
0
        string GetMetadataUrl(string tid, string ver)
        {
            StatusWrite("Getting meta NcaId..");
            string url = $"{Settings.GetCdnUrl()}/t/a/{tid}/{ver}";
            string ret = "";

            try {
                WebResponse response = HTTP.Request("HEAD", url);
                ret = $"{Settings.GetCdnUrl()}/c/a/{response.Headers.Get("X-Nintendo-Content-ID")}";
                response.Close();
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }
            return(ret);
        }
Ejemplo n.º 6
0
        void DownloadFile(string url, string filename)
        {
            try {
                //Setup webrequest
                DateTime    startTime = DateTime.UtcNow;
                WebResponse response  = HTTP.Request("GET", url);
                int         max       = (int)(response.ContentLength / 0x1000);
                ThreadSafe(() => {
                    progBar.Maximum = max < 0x1000 ? 1 : max;
                    progBar.Step    = 1;

                    //Read response in chunks of 0x1000 bytes
                    string filepath = Path.Combine(Application.StartupPath, filename);
                    using (Stream responseStream = response.GetResponseStream()) {
                        using (Stream fileStream = File.OpenWrite(filepath)) {
                            byte[] buffer = new byte[0x1000];
                            int bytesRead;
                            do
                            {
                                bytesRead = responseStream.Read(buffer, 0, 0x1000);
                                Console.WriteLine("Bytesread: " + bytesRead.ToString("X8"));
                                fileStream.Write(buffer, 0, bytesRead);
                                if ((DateTime.UtcNow - startTime).TotalMinutes > 5)
                                {
                                    throw new ApplicationException("Download timed out");
                                }
                                progBar.PerformStep();
                            } while (bytesRead > 0);
                        }
                    }
                });
                response.Close();
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }