public void WriteLocalizationBundlesToDisk(byte[] bytes, string version)
    {
        if (HasCachedVersion(version))
        {
            return;
        }

        try {
            if (Directory.Exists(_localizationBundlePath))
            {
                Directory.Delete(_localizationBundlePath, true);
            }
        } catch (IOException e) {
            this.LogError("Exception deleting directory '" + _localizationBundlePath + "': " + e);
        }

        Directory.CreateDirectory(_localizationBundlePath);

        using (MemoryStream stream = new MemoryStream(bytes, 0, bytes.Length))
            using (ZipInputStream zipFile = new ZipInputStream((stream)))
            {
                ZipEntry entry = zipFile.GetNextEntry();
                while (entry != null)
                {
                    string dir = Path.GetDirectoryName(entry.Name);
                    if (!string.IsNullOrEmpty(dir))
                    {
                        Directory.CreateDirectory(Path.Combine(_localizationBundlePath, dir));
                    }
                    if (entry.IsFile)
                    {
                        string filePath = Path.Combine(_localizationBundlePath, entry.Name);
                        using (var file = File.Open(filePath, FileMode.Create))
                        {
                            byte[] buffer = new byte[2048];
                            while (true)
                            {
                                int size = zipFile.Read(buffer, 0, buffer.Length);
                                if (size > 0)
                                {
                                    file.Write(buffer, 0, size);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        FileUtils.SetNoBackupFlag(filePath);
                    }
                    entry = zipFile.GetNextEntry();
                }
            }

        _localPrefs.SetSharedString(LOC_VERSION_KEY, version);
    }
예제 #2
0
 public void SavePlayerRecord(string playerRcord)
 {
     _localPrefs.SetSharedString(PlayerPrefs.PLAYER_RECORD.ToPrefsKey(), playerRcord);
 }