Example #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            js.MaxJsonLength = int.MaxValue;

            byte[]        jsonData;
            List <string> links = new List <string>();
            string        fileURL;
            string        fileName;

            Task.Factory.StartNew(() =>
            {
                groupBoxDL.Invoke(new Action(() => groupBoxDL.Enabled = false));
                using (var client = new WebClient())
                {
                    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    client.Headers.Add("user-agent", "SWUF");
                    try
                    {
                        jsonData = client.DownloadData(catalogURL);
                    }
                    catch
                    {
                        MessageBox.Show("Unable to download remote_catalog.json file");
                        return;
                    }
                }
                File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "remote_catalog.json"), jsonData);

                string jsonText             = Encoding.UTF8.GetString(jsonData);
                RemoteCatalog remoteCatalog = (RemoteCatalog)js.Deserialize <RemoteCatalog>(jsonText);
                string[] m_InternalIds      = remoteCatalog.m_InternalIds;

                foreach (string line in m_InternalIds)
                {
                    if (line.Contains(".bundle"))
                    {
                        fileName = line.Replace(@"api://AssetBundle/Android/rsc/", "");
                        fileURL  = baseURL + fileName;
                        links.Add(fileURL);
                    }
                }

                File.WriteAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Links.txt"), links);


                MessageBox.Show("Saved");
                groupBoxDL.Invoke(new Action(() => groupBoxDL.Enabled = true));
            });
        }
Example #2
0
        private void buttonDL_Click(object sender, EventArgs e)
        {
            js.MaxJsonLength = int.MaxValue;

            byte[] jsonData;
            string fileURL;
            string filePath;
            string fileName;
            int    count = 0;
            int    total = 0;

            Task.Factory.StartNew(() =>
            {
                groupBoxDL.Invoke(new Action(() => groupBoxDL.Enabled = false));
                using (var client = new WebClient())
                {
                    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                    client.Headers.Add("user-agent", "SWUF");
                    try
                    {
                        jsonData = client.DownloadData(catalogURL);
                    }
                    catch
                    {
                        MessageBox.Show("Unable to download remote_catalog.json file");
                        return;
                    }
                }
                File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "remote_catalog.json"), jsonData);

                if (!Directory.Exists(dataPath))
                {
                    Directory.CreateDirectory(dataPath);
                }

                string jsonText             = Encoding.UTF8.GetString(jsonData);
                RemoteCatalog remoteCatalog = (RemoteCatalog)js.Deserialize <RemoteCatalog>(jsonText);
                string[] m_InternalIds      = remoteCatalog.m_InternalIds;

                foreach (string line in m_InternalIds)
                {
                    if (line.Contains(".bundle"))
                    {
                        total++;
                    }
                }



                foreach (string line in m_InternalIds)
                {
                    if (line.Contains(".bundle"))
                    {
                        fileName = line.Replace(@"api://AssetBundle/Android/rsc/", "");
                        fileURL  = baseURL + fileName;
                        filePath = Path.Combine(dataPath, fileName);

                        using (var client = new WebClient())
                        {
                            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                            client.Headers.Add("user-agent", "AGA");
                            try
                            {
                                client.DownloadFile(fileURL, filePath);
                            }
                            catch
                            {
                                try
                                {
                                    client.DownloadFile(fileURL, filePath);
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                        }
                        count++;
                        buttonDL.Invoke(new Action(() => buttonDL.Text = count.ToString() + "/" + total.ToString()));
                    }
                }
                MessageBox.Show("Downloaded " + count.ToString() + " out of " + total.ToString() + " files");
                buttonDL.Invoke(new Action(() => buttonDL.Text        = "Download"));
                groupBoxDL.Invoke(new Action(() => groupBoxDL.Enabled = true));
            });
        }