internal void DL()
        {
            acceptButton.interactable = false;
            var rnd = new Random();

            downloadRequest = DownloadAsset(assetDB);
            downloadRequest.client.DownloadProgressChanged += wc_progChange;
            downloadRequest.client.DownloadFileCompleted   += wc_complete;
        }
예제 #2
0
        internal static DownloadRequestResponse DownloadAsset(DownloadsDatabase db)
        {
            DownloadRequestResponse resp = new DownloadRequestResponse();
            var rng = new Random();


            Rarity        rolledRarity       = new Rarity();
            List <String> rolledType         = new List <string>();
            int           amountOfRolledType = 0;

            switch (Random.Range(0, 5))
            {
            case 0:
                rolledRarity = db.Tier1;
                Plugin.Log.Info("Rolled Tier 1");
                resp.tier = 1;
                break;

            case 1:
                rolledRarity = db.Tier2;
                Plugin.Log.Info("Rolled Tier 2");
                resp.tier = 2;
                break;

            case 2:
                rolledRarity = db.Tier3;
                Plugin.Log.Info("Rolled Tier 3");
                resp.tier = 3;
                break;

            case 3:
                rolledRarity = db.Tier4;
                Plugin.Log.Info("Rolled Tier 4");
                resp.tier = 4;
                break;

            case 4:
                rolledRarity = db.Tier5;
                Plugin.Log.Info("Rolled Tier 5");
                resp.tier = 5;
                break;
            }
            string folder  = "";
            int    maxtype = 4;

            if (!AssetModDetection.MenuFonts)
            {
                maxtype = 3;
            }
            var a = Random.Range(0, maxtype);

            if (a.Equals(rollcat1))
            {
                a = Random.Range(0, maxtype);
            }
            rollcat1 = a;
            switch (a)
            {
            case 0:
                rolledType         = rolledRarity.Sabers;
                amountOfRolledType = rolledType.Count;
                folder             = "UserData\\LootSaber\\Asset Cache\\CustomSabers";
                Plugin.Log.Info("Rolled Saber");
                resp.assetType = "Saber";
                break;

            case 1:
                rolledType         = rolledRarity.Notes;
                amountOfRolledType = rolledType.Count;
                folder             = "UserData\\LootSaber\\Asset Cache\\CustomNotes";
                Plugin.Log.Info("Rolled Note");
                resp.assetType = "Note";
                break;

            case 2:
                rolledType         = rolledRarity.Platforms;
                amountOfRolledType = rolledType.Count;
                folder             = "UserData\\LootSaber\\Asset Cache\\CustomPlatforms";
                Plugin.Log.Info("Rolled Platform");
                resp.assetType = "Platform";
                break;

            case 3:
                rolledType         = rolledRarity.MenuFonts;
                amountOfRolledType = rolledType.Count;
                folder             = "UserData\\LootSaber\\Asset Cache\\UserData\\CustomMenuText\\Fonts";
                Plugin.Log.Info("Rolled Menu Font");
                resp.assetType = "Menu Text Font";
                break;
            }
            var URL = rolledType.ElementAt(Random.Range(0, amountOfRolledType));

            var    client    = new WebClient();
            string _realname = URL.Substring(URL.LastIndexOf("/") + 1).Replace("%20", " ");

            if (_realname.Contains("?"))
            {
                _realname = _realname.Substring(0, _realname.IndexOf("?"));
            }



            string fileSavePath = UnityGame.InstallPath + "\\" + folder + "\\" + _realname;

            try
            {
                Plugin.Log.Notice("Downloading " + _realname + " From " + URL);
                client.DownloadFileAsync(
                    new Uri(URL),
                    fileSavePath
                    );
                resp.client = client;
            }
            catch (Exception)
            {
                //if the folder doesn't exist, create it and try again
                Directory.CreateDirectory(UnityGame.InstallPath + "\\" + folder);
                client.DownloadFileAsync(
                    new Uri(URL),
                    fileSavePath
                    );
                resp.client = client;
            }
            resp.filePath = fileSavePath;
            return(resp);
        }