示例#1
0
 private void LoadSets()
 {
     if (AllSetsUrlZipped)
     {
         UnityExtensionMethods.ExtractZip(SetsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath);
     }
     if (AllSetsUrlWrapped)
     {
         UnityExtensionMethods.UnwrapFile(SetsFilePath);
     }
     LoadJsonFromFile(SetsFilePath, LoadSetFromJToken, SetDataIdentifier);
 }
示例#2
0
        private void LoadCards(int page)
        {
            string cardsFilePath = CardsFilePath + (page != AllCardsUrlPageCountStartIndex ? page.ToString() : string.Empty);

            try
            {
                if (AllCardsUrlZipped)
                {
                    UnityExtensionMethods.ExtractZip(cardsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath);
                }
                if (AllCardsUrlWrapped)
                {
                    UnityExtensionMethods.UnwrapFile(cardsFilePath);
                }
                LoadJsonFromFile(cardsFilePath, LoadCardFromJToken, CardDataIdentifier);
            }
            catch (Exception e)
            {
                Error += e.Message + e.StackTrace + Environment.NewLine;
            }
        }
        public IEnumerator Download()
        {
            if (IsDownloading)
            {
                yield break;
            }
            IsDownloading = true;

            // We should always first get the *Game:Name*.json file and read it before doing anything else
            DownloadProgress = 0f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: CardGameDef...";
            yield return(UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, GameFilePath));

            ReadProperties();
            if (!HasReadProperties)
            {
                // ReadProperties() should have already populated the Error
                IsDownloading = false;
                HasDownloaded = false;
                yield break;
            }

            DownloadProgress = 1f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Banner";
            if (!string.IsNullOrEmpty(BannerImageUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(BannerImageUrl, BannerImageFilePath));
            }

            DownloadProgress = 2f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: CardBack";
            if (!string.IsNullOrEmpty(CardBackImageUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(CardBackImageUrl, CardBackImageFilePath));
            }

            DownloadProgress = 3f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Boards";
            foreach (GameBoardUrl boardUrl in GameBoardUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(boardUrl.Url, GameBoardsFilePath + "/" + boardUrl.Id + "." + GameBoardFileType));
            }

            DownloadProgress = 4f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Decks";
            foreach (DeckUrl deckUrl in DeckUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(deckUrl.Url, DecksFilePath + "/" + deckUrl.Name + "." + DeckFileType));
            }

            DownloadProgress = 5f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: AllSets.json";
            string setsFilePath = SetsFilePath + (AllSetsUrlZipped ? UnityExtensionMethods.ZipExtension : string.Empty);

            if (!string.IsNullOrEmpty(AllSetsUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(AllSetsUrl, setsFilePath));
            }
            if (AllSetsUrlZipped)
            {
                UnityExtensionMethods.ExtractZip(setsFilePath, GameDirectoryPath);
            }
            if (AllSetsUrlWrapped)
            {
                UnityExtensionMethods.UnwrapFile(SetsFilePath);
            }

            if (!string.IsNullOrEmpty(AllCardsUrl))
            {
                for (int page = AllCardsUrlPageCountStartIndex; page < AllCardsUrlPageCountStartIndex + AllCardsUrlPageCount; page++)
                {
                    DownloadProgress = (6f + page - AllCardsUrlPageCountStartIndex) / (7f + AllCardsUrlPageCount - AllCardsUrlPageCountStartIndex);
                    DownloadStatus   = $"Downloading: Cards: {page,5} / {AllCardsUrlPageCountStartIndex + AllCardsUrlPageCount}";
                    string cardsUrl = AllCardsUrl;
                    if (AllCardsUrlPageCount > 1 && string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                    {
                        cardsUrl += AllCardsUrlPageIdentifier + page;
                    }
                    string cardsFile = CardsFilePath;
                    if (page != AllCardsUrlPageCountStartIndex)
                    {
                        cardsFile += page.ToString();
                    }
                    if (AllCardsUrlZipped)
                    {
                        cardsFile += UnityExtensionMethods.ZipExtension;
                    }
                    string jsonBody = null;
                    if (!string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                    {
                        jsonBody  = "{" + AllCardsUrlPostBodyContent;
                        jsonBody += AllCardsUrlPageIdentifier + page;
                        jsonBody += "}";
                    }
                    yield return(UnityExtensionMethods.SaveUrlToFile(cardsUrl, cardsFile, jsonBody));

                    if (AllCardsUrlZipped)
                    {
                        UnityExtensionMethods.ExtractZip(cardsFile, GameDirectoryPath);
                    }
                    if (AllCardsUrlWrapped)
                    {
                        UnityExtensionMethods.UnwrapFile(cardsFile.EndsWith(UnityExtensionMethods.ZipExtension)
                            ? cardsFile.Remove(cardsFile.Length - UnityExtensionMethods.ZipExtension.Length) : cardsFile);
                    }
                    // Sometimes, we need to get the AllCardsUrlPageCount from the first page of AllCardsUrl
                    if (page == AllCardsUrlPageCountStartIndex && !string.IsNullOrEmpty(AllCardsUrlPageCountIdentifier))
                    {
                        LoadCards(page);
                    }
                }
            }

            IsDownloading  = false;
            DownloadStatus = "Complete!";
            HasDownloaded  = true;
            HasLoaded      = false;
        }