Ejemplo n.º 1
0
        public static void OpenDownloadForm(List <TitleInfo> list, bool createFolderOnly = false)
        {
            _createFolderOnly = createFolderOnly;

            Action <DialogTitlePatch.Result> openDownload = (DialogTitlePatch.Result e) =>
            {
                AppDomain.CurrentDomain.DoCallBack(() =>
                {
                    frmDownload frm = new frmDownload();
                    frm.TitleQueue  = list;
                    if (list.Count > 1)
                    {
                        frm.AutoClose = true;

                        if (e.Game)
                        {
                            frm.AutoDownloadType |= frmDownload.DownloadType.Game;
                        }

                        if (e.Update)
                        {
                            frm.AutoDownloadType |= frmDownload.DownloadType.Update;
                        }

                        if (e.DLC)
                        {
                            frm.AutoDownloadType |= frmDownload.DownloadType.DLC;
                        }

                        if (frm.ChooseFolder() == false)
                        {
                            return;
                        }
                    }

                    Program.FormContext.AddForm(frm);
                    frm.BringToFront();
                });
            };

            if (list.Count > 1)
            {
                DialogTitlePatch dialog = new DialogTitlePatch();
                dialog.OKClicked += (object s, DialogTitlePatch.Result e) => {
                    openDownload(e);
                };
                dialog.ShowDialog();
            }
            else
            {
                openDownload(new DialogTitlePatch.Result());
            }
        }
Ejemplo n.º 2
0
        public static void DownloadMissing(string tmdPath, bool autoClose = false)
        {
            if (!File.Exists(tmdPath))
            {
                return;
            }

            FileInfo info = new FileInfo(tmdPath);

            TMD tmd           = new TMD(File.ReadAllBytes(tmdPath));
            var onlineTMDTask = NUS.DownloadTMD(tmd.TitleID);

            onlineTMDTask.Wait();
            TMD onlineTMD = onlineTMDTask.Result;


            if (!tmd.rawBytes.SequenceEqual(onlineTMD.rawBytes))
            {
                MessageBox.Show(Localization.Strings.RepairFailed, Localization.Strings.Error);
                return;
            }

            List <DownloadItem> queue = new List <DownloadItem> {
            };
            var URLTask = NUS.GetTitleContentURLs(tmd, true);

            URLTask.Wait();
            NUS.UrlFilenamePair[] URLs = URLTask.Result;

            AppDomain.CurrentDomain.DoCallBack(() =>
            {
                frmDownload frm = new frmDownload();
                frm.DownloadQueue.Add(new DownloadItem(tmd.TitleID, tmd, URLs, new byte[] { }, info.DirectoryName));
                frm.AutoClose    = autoClose;
                frm.DownloadPath = info.DirectoryName;
                frm.lblDownloadingMetadata.Dispose();
                Program.FormContext.AddForm(frm);
            });
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                System.Version version        = Assembly.GetExecutingAssembly().GetName().Version;
                SemVersion     currentVersion = new SemVersion(version.Major, version.Minor, version.Build);
                HttpWebRequest request        = WebRequest.Create("https://api.github.com/repos/DanTheMan827/uTikDownloadHelper/releases") as HttpWebRequest;
                request.UserAgent = "uTikDownloadHelper " + currentVersion;
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader    reader   = new System.IO.StreamReader(response.GetResponseStream(), ASCIIEncoding.UTF8);

                dynamic json = JArray.Parse(reader.ReadToEnd());

                SemVersion newestVersion = SemVersion.Parse(((String)json[0].tag_name).Substring(1));

                if (newestVersion > currentVersion)
                {
                    if (MessageBox.Show(String.Format("v{0} is now available, you have v{1}.\r\n\r\nDo you want to visit the download page?", newestVersion.ToString(), currentVersion.ToString()), "New Version", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Process.Start((String)json[0].html_url);
                        return;
                    }
                }
            }
            catch (Exception ex) { }

            Directory.CreateDirectory(Common.TicketsPath);
            if (Common.Settings.ticketWebsite == null)
            {
                Common.Settings.ticketWebsite = "";
            }

            if (args.Length == 0)
            {
                using (frmList frm = new frmList())
                {
                    FormContext.AddForm(frm);
                    Application.Run(FormContext);
                }
                return;
            }

            if (args[0].ToLower().EndsWith(".tmd"))
            {
                if (File.Exists(args[0]))
                {
                    frmDownload.DownloadMissing(args[0], true);
                    Application.Run(FormContext);
                }

                return;
            }

            string ticketInputPath = args[0];

            Byte[] ticket = { };

            if (ticketInputPath.ToLower().StartsWith("http"))
            {
                try
                {
                    ticket = (new System.Net.WebClient()).DownloadData(ticketInputPath);
                } catch (Exception e)
                {
                    MessageBox.Show(e.Message.ToString(), "Error Downloading Ticket");
                    return;
                }
            }
            else
            {
                ticket = File.ReadAllBytes(ticketInputPath);
            }

            if (ticket.Length < 848)
            {
                MessageBox.Show("Invalid Ticket");
            }

            using (var frm = new frmDownload()){
                string    hexID = HelperFunctions.getTitleIDFromTicket(ticket);
                TitleInfo info  = new TitleInfo(hexID, "", hexID, "", "", true);
                info.ticket = ticket;
                frm.TitleQueue.Add(info);
                FormContext.AddForm(frm);
                Application.Run(FormContext);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Directory.CreateDirectory(Common.TicketsPath);
            if (Common.Settings.ticketWebsite == null)
            {
                Common.Settings.ticketWebsite = "";
            }

            if (args.Length == 0)
            {
                using (frmList frm = new frmList())
                {
                    FormContext.AddForm(frm);
                    Application.Run(FormContext);
                }
                return;
            }

            if (args[0].ToLower().EndsWith(".tmd"))
            {
                if (File.Exists(args[0]))
                {
                    frmDownload.DownloadMissing(args[0], true);
                    Application.Run(FormContext);
                }

                return;
            }

            string ticketInputPath = args[0];

            Byte[] ticket = { };

            if (ticketInputPath.ToLower().StartsWith("http"))
            {
                try
                {
                    ticket = (new System.Net.WebClient()).DownloadData(ticketInputPath);
                } catch (Exception e)
                {
                    MessageBox.Show(e.Message.ToString(), "Error Downloading Ticket");
                    return;
                }
            }
            else
            {
                ticket = File.ReadAllBytes(ticketInputPath);
            }

            if (ticket.Length < 848)
            {
                MessageBox.Show("Invalid Ticket");
            }

            using (var frm = new frmDownload()){
                string    hexID = HelperFunctions.getTitleIDFromTicket(ticket);
                TitleInfo info  = new TitleInfo(hexID, "", hexID, "", "", true);
                info.ticket = ticket;
                frm.TitleQueue.Add(info);
                FormContext.AddForm(frm);
                Application.Run(FormContext);
            }
        }