Beispiel #1
0
        /// <summary>
        /// Coroutine that downloads the update file and installs it
        /// </summary>
        /// <returns></returns>
        public IEnumerator <float> DownloadUpdate()
        {
            if (state == UpdaterState.Ready)
            {
                // Creates a web request to the github repository based on the selected update stream
                if (updateStream == UpdateStream.Beta)
                {
                    request = new UnityWebRequest("https://github.com/Cibbi/Toony-standard/archive/" + githubBetaJSON.sha + ".zip");
                    file    = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.zip");
                }
                else
                {
                    request = new UnityWebRequest(githubReleaseJSON.assets[0].browser_download_url);
                    file    = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.unitypackage");
                }

                request.method          = UnityWebRequest.kHttpVerbGET;
                file.removeFileOnAbort  = true;
                request.downloadHandler = file;
                request.SendWebRequest();
                state = UpdaterState.Downloading;
                // Main check cycle that waits for the downloaded file, like the update check execution is paused every cycle to not block
                // normal window execution
                while (state == UpdaterState.Downloading)
                {
                    yield return(0.5f);

                    // Executed if the request is done
                    if (request.isDone)
                    {
                        state = UpdaterState.Downloaded;

                        TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));

                        // If the update stream is the beta one the downloaded file is a zip file, meaning that we have to extract it manually, fortunately a guy called Yallie made a simple
                        // extraction class that handles the basic stuff needed here, check him over https://github.com/yallie/unzip
                        if (updateStream == UpdateStream.Beta)
                        {
                            string localFolder = TSConstants.LocalShaderFolder;
                            Unzip  zip         = new Unzip(Application.dataPath + "/toonyStandard.zip");
                            // Deleting the old Toony standard version
                            if (Directory.Exists(TSConstants.LocalShaderFolder))
                            {
                                Directory.Delete(TSConstants.LocalShaderFolder, true);
                            }
                            // For each file in the zip we change the github repository path with the more user friendly one used on the releases, and then extract that file in that path
                            foreach (string fileName in zip.FileNames)
                            {
                                string newDir = fileName.Replace("Toony-standard-" + githubBetaJSON.sha, localFolder);
                                if (!Directory.Exists(Path.GetDirectoryName(newDir)))
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(newDir));
                                }
                                zip.Extract(fileName, newDir);
                            }
                            // Disposing of the zip, this is important cause without doing it the zip file cannot be deleted afterwards
                            zip.Dispose();
                            // Creation of the updated version.json file for this beta version, cause the one that comes in the zip does not contain the sha of the commit used when checking updates
                            // Since it's impossible to know a commit sha before doing such commit.
                            LocalVersionJSON local = new LocalVersionJSON();
                            local.beta      = true;
                            local.betaSha   = githubBetaJSON.sha;
                            local.version   = "beta";
                            local.lastCheck = DateTime.Now.ToString();
                            File.WriteAllText(TSConstants.LocalJSONPath, JsonUtility.ToJson(local));
                            // The asset database is refreshed to be sure that the zip file is actually detected from the asset database for its deletion
                            File.Delete(Application.dataPath + "/toonyStandard.zip");
                            AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                        }
                        // If the update stream is the release one the downloaded file is the latest unitypackage that can be found here https://github.com/Cibbi/Toony-standard/releases
                        // Since it's a unitypackage its installation is relatively easy, but we still delete the old version first for safety
                        else
                        {
                            if (Directory.Exists(TSConstants.LocalShaderFolder))
                            {
                                Directory.Delete(TSConstants.LocalShaderFolder, true);
                            }
                            AssetDatabase.ImportPackage(Application.dataPath + "/toonyStandard.unitypackage", false);
                            AssetDatabase.Refresh();
                            AssetDatabase.DeleteAsset("Assets/toonyStandard.unitypackage");
                        }

                        File.WriteAllText(TSConstants.OldSettingsJSONPath, JsonUtility.ToJson(settings));
                    }
                    // Executed if the request got an error response
                    if (request.isNetworkError || request.isHttpError)
                    {
                        Debug.Log("Toony Standard: network error during downlaod, please retry later");
                    }
                }
            }
        }
Beispiel #2
0
        private void RetrieveAllSongs(bool fullRefresh)
        {
            var stopwatch = new Stopwatch();

            if (fullRefresh)
            {
                CustomLevels.Clear();
                CustomWIPLevels.Clear();
                CachedWIPLevels.Clear();
                Collections.levelHashDictionary.Clear();
                Collections.hashLevelDictionary.Clear();
                foreach (var folder in SeperateSongFolders)
                {
                    folder.Levels.Clear();
                }
            }
            HashSet <string> foundSongPaths = fullRefresh ? new HashSet <string>() : new HashSet <string>(Hashing.cachedSongHashData.Keys);

            var baseProjectPath  = CustomLevelPathHelper.baseProjectPath;
            var customLevelsPath = CustomLevelPathHelper.customLevelsDirectoryPath;

            Action job = delegate
            {
                try
                {
                    var path = CustomLevelPathHelper.baseProjectPath;
                    path = path.Replace('\\', '/');

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

                    if (!Directory.Exists(baseProjectPath + "/CustomWIPLevels"))
                    {
                        Directory.CreateDirectory(baseProjectPath + "/CustomWIPLevels");
                    }
                    if (fullRefresh)
                    {
                        try
                        {
                            var cachePath = path + "/CustomWIPLevels/Cache";
                            if (!Directory.Exists(cachePath))
                            {
                                Directory.CreateDirectory(cachePath);
                            }
                            var cache = new DirectoryInfo(cachePath);
                            foreach (var file in cache.GetFiles())
                            {
                                file.Delete();
                            }
                            foreach (var folder in cache.GetDirectories())
                            {
                                folder.Delete(true);
                            }
                            var zips = Directory.GetFiles(path + "/CustomWIPLevels", "*.zip", SearchOption.TopDirectoryOnly);
                            foreach (var zip in zips)
                            {
                                var unzip = new Unzip(zip);
                                try
                                {
                                    unzip.ExtractToDirectory(cachePath + "/" + new FileInfo(zip).Name);
                                }
                                catch (Exception ex)
                                {
                                    Logging.logger.Warn("Failed to extract zip: " + zip + ": " + ex);
                                }
                                unzip.Dispose();
                            }

                            var cacheFolders = Directory.GetDirectories(cachePath).ToArray();
                            foreach (var cachedFolder in cacheFolders)
                            {
                                var results = Directory.GetFiles(cachedFolder, "info.dat", SearchOption.AllDirectories);
                                if (results.Length == 0)
                                {
                                    Logging.Log("Folder: '" + cachedFolder + "' is missing info.dat files!", LogSeverity.Notice);
                                    continue;
                                }
                                foreach (var result in results)
                                {
                                    try
                                    {
                                        var songPath = Path.GetDirectoryName(result.Replace('\\', '/'));
                                        if (!fullRefresh)
                                        {
                                            if (CachedWIPLevels.ContainsKey(songPath))
                                            {
                                                var c = CachedWIPLevels[songPath];//.FirstOrDefault(x => x.customLevelPath == songPath);
                                                if (c != null)
                                                {
                                                    continue;
                                                }
                                            }
                                        }
                                        StandardLevelInfoSaveData saveData = GetStandardLevelInfoSaveData(songPath);
                                        if (saveData == null)
                                        {
                                            continue;
                                        }

                                        HMMainThreadDispatcher.instance.Enqueue(delegate
                                        {
                                            if (_loadingCancelled)
                                            {
                                                return;
                                            }
                                            var level = LoadSong(saveData, songPath, out string hash);
                                            if (level != null)
                                            {
                                                CachedWIPLevels[songPath] = level;
                                            }
                                        });
                                    }
                                    catch (Exception ex)
                                    {
                                        Logging.logger.Notice("Failed to load song from " + cachedFolder + ": " + ex);
                                    }
                                }
                            }
                        }