public void SaveLanguages(bool unloadAll, PersistentStorage.eFileType fileLocation = PersistentStorage.eFileType.Temporal) { if (!AllowUnloadingLanguages()) { return; } // Some consoles don't allow IO access if (!PersistentStorage.CanAccessFiles()) { return; } for (int i = 0; i < mLanguages.Count; ++i) { var data = Export_Language_to_Cache(i, IsCurrentLanguage(i)); if (string.IsNullOrEmpty(data)) { continue; } PersistentStorage.SaveFile(PersistentStorage.eFileType.Temporal, GetSavedLanguageFileName(i), data); } if (unloadAll) { for (int i = 0; i < mLanguages.Count; ++i) { if (unloadAll && !IsCurrentLanguage(i)) { UnloadLanguage(i); } } } }
string UpdateFilename(PersistentStorage.eFileType fileType, string fileName) { switch (fileType) { case PersistentStorage.eFileType.Persistent: fileName = Application.persistentDataPath + "/" + fileName; break; case PersistentStorage.eFileType.Temporal: fileName = Application.temporaryCachePath + "/" + fileName; break; case PersistentStorage.eFileType.Streaming: fileName = Application.streamingAssetsPath + "/" + fileName; break; } return(fileName); }
public virtual bool HasFile(PersistentStorage.eFileType fileType, string fileName, bool logExceptions = true) { if (!CanAccessFiles()) { return(false); } try { fileName = UpdateFilename(fileType, fileName); return(System.IO.File.Exists(fileName)); } catch (Exception e) { if (logExceptions) { Debug.LogError("Error requesting file '" + fileName + "'\n" + e); } return(false); } }
public virtual string LoadFile(PersistentStorage.eFileType fileType, string fileName, bool logExceptions = true) { if (!CanAccessFiles()) { return(null); } try { fileName = UpdateFilename(fileType, fileName); return(System.IO.File.ReadAllText(fileName, System.Text.Encoding.UTF8)); } catch (Exception e) { if (logExceptions) { Debug.LogError("Error loading file '" + fileName + "'\n" + e); } return(null); } }
public virtual bool SaveFile(PersistentStorage.eFileType fileType, string fileName, string data, bool logExceptions = true) { if (!CanAccessFiles()) { return(false); } try { fileName = UpdateFilename(fileType, fileName); System.IO.File.WriteAllText(fileName, data, System.Text.Encoding.UTF8); return(true); } catch (Exception e) { if (logExceptions) { Debug.LogError("Error saving file '" + fileName + "'\n" + e); } return(false); } }