Exemple #1
0
 private void DoLoadErrorCallback(string message, string systemId, string path, bool det, LoadErrorType type = LoadErrorType.Unknown)
 {
     OnLoadError?.Invoke(this, new RomErrorArgs(message, systemId, path, det, type));
 }
Exemple #2
0
 private static void RaiseLoadError(string texName, string error)
 {
     OnLoadError?.Invoke(texName, error);
 }
    public static void Load(string fileName, bool encrypt = false)
    {
        if (fileName.Contains(ENCRYPTION_SYMBOL))
        {
            fileName = fileName.Replace(ENCRYPTION_SYMBOL, "");
        }
        string fullName       = fileName + filesExtension;
        string fullCryptoName = fileName + ENCRYPTION_SYMBOL + filesExtension;
        string filePath       = Data.FilesPath + fullName;
        string cryptoFilePath = Data.FilesPath + fullCryptoName;

        string json;
        bool   normalFileExists = File.Exists(filePath);
        bool   cryptoFileExists = File.Exists(cryptoFilePath);

        if (normalFileExists) // Not encrypted file exists
        {
            Data.enableEncryption = false;
            try
            {
                json = File.ReadAllText(filePath);
                JsonUtility.FromJsonOverwrite(json, Data);
                currentFile = fileName;

                if (encrypt) // Save loaded file as encrypted
                {
                    Data.enableEncryption = true;
                    Save(fileName, encrypt);
                    currentFile = fileName;
                }
            }
            catch                         // The file is damaged or encrypted
            {
                json = Decrypt(filePath); // Try to decrypt
                if (json != "")
                {
                    JsonUtility.FromJsonOverwrite(json, Data);
                    currentFile = fileName;
                    onLoadFinish?.Invoke();
                }
                else // File is damaged
                {
                    onLoadError?.Invoke(fullCryptoName, filePath);
                }
            }
        }
        if (cryptoFileExists)                 // File is encrypted
        {
            if (normalFileExists && !encrypt) // We don't need encrypted file - delete it
            {
                File.Delete(cryptoFilePath);
            }
            else
            {
                Data.enableEncryption = true;
                json = Decrypt(cryptoFilePath);
                if (json != "")
                {
                    JsonUtility.FromJsonOverwrite(json, Data);
                    currentFile = fileName;
                }
                else // File is marked as encrypted, but decryption has been failed
                {
                    try
                    {
                        json = File.ReadAllText(cryptoFilePath); // Try to read it straightforward
                        JsonUtility.FromJsonOverwrite(json, Data);
                        currentFile = fileName;
                    }
                    catch // File is damaged?
                    {
                        onLoadError?.Invoke(fullCryptoName, filePath);
                    }
                }
                currentFile = fileName;
            }
        }
        if (!normalFileExists && !cryptoFileExists) // No file found, create new empty one
        {
            ClearAll();
            Save(fileName, encrypt);
            currentFile = fileName;
        }
    }
Exemple #4
0
 public void OnLoadErrorCallback(int?soundId, string error)
 {
     OnLoadError?.Invoke(new HowlErrorEventArgs {
         SoundId = soundId, Error = error
     });
 }
 private static void RaiseLoadError(string contentName, string error)
 {
     OnLoadError?.Invoke(contentName, error);
 }