Exemplo n.º 1
0
        /// <summary>
        /// Clears Unused Cache File
        /// </summary>
        /// <param name="fileNo">FileNo that is cleared. Set to 0 to clear non-Current Cache</param>
        public static void ClearUnusedCache(int fileNo = 0)
        {
            LoggingLevel log = LanguageManager.Instance.GetLoggingLevel();

            // Clear Unused File
            if (fileNo.Equals(0))
            {
                fileNo = CurrentFile.Equals(1) ? 2 : 1;
            }
            string path = string.Format("{0}/Cache{1}", CachePath, fileNo);

            try
            {
                if (!Directory.Exists(CachePath))
                {
                    LoggingLevel.Debug.Log("ResourceLoader: No Unused Cache to Clear", log);
                    return; // Directory & Files don't exist
                }
                File.Delete(path);
                LoggingLevel.Info.Log(string.Format("ResourceLoader: Cleared Cache file [{0}]", path), log);
            }
            catch (FileNotFoundException)
            {
                LoggingLevel.Debug.Log("ResourceLoader: No Unused Cache to Clear", log);
                // Cache does not exist (yet). Do Nothing
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves a LanguageMap to Cache
        /// </summary>
        /// <param name="map">Map to Save</param>
        private static void SaveCachedMap(string map)
        {
            LoggingLevel log = LanguageManager.Instance.GetLoggingLevel();
            // Save to proper file. Don't forget to clear other file to save disk-space
            int    newFilePath = CurrentFile.Equals(1) ? 2 : 1;
            string fullPath    = string.Format("{0}/Cache{1}", CachePath, newFilePath);

            try
            {
                LoggingLevel.Info.Log(string.Format("ResourceLoader: [SAVE] Saving Cache String to [{0}]", fullPath), log);
                if (!Directory.Exists(CachePath))
                {
                    LoggingLevel.Debug.Log(string.Format("ResourceLoader: [SAVE] Creating Directory [{0}]", CachePath), log);
                    Directory.CreateDirectory(CachePath);
                }
                FileStream fs;
                if (!File.Exists(fullPath))
                {
                    fs = File.Create(fullPath);
                    LoggingLevel.Debug.Log(string.Format("ResourceLoader: [SAVE] Created File at [{0}]", fullPath), log);
                }
                else
                {
                    fs = File.Open(fullPath, FileMode.OpenOrCreate);
                    LoggingLevel.Debug.Log(string.Format("ResourceLoader: [SAVE] Opened File at [{0}]", fullPath), log);
                }
                fs.Close();
                File.WriteAllText(fullPath, map);
                LoggingLevel.Info.Log(string.Format("ResourceLoader: [SAVE] Saved Cache to [{0}], Cache-Content: {1}", fullPath, map), log);
                UpdateFileNo();
            }
            catch (Exception e)
            {
                // TODO: Find relevant Exceptions
                LoggingLevel.Error.Log("ResourceLoader: [SAVE] Exception while saving Cache", log);
                throw e;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Updates current file number. Called when File is finished downloading.
 /// </summary>
 private static void UpdateFileNo()
 {
     PlayerPrefs.SetInt(PlayerPrefKey_LanguageFileNo, CurrentFile.Equals(1) ? 2 : 1);
     LoggingLevel.Development.Log(string.Format("ResourceLoader: Updated File No. for Cache. New No [{0}]", CurrentFile), LanguageManager.Instance.GetLoggingLevel());
 }