#if OLD_STORAGE
using System;
using System.Runtime.InteropServices;
using UnityEngine;

public enum StorageFilename {
    MainData,
    SettingsData,
    WalletData,
    PurchaserData,
}

/// 古いのでMyStorageManagerを使用して下さい
public static class StorageManager {

//    public static void Save<T>(StorageFilename filename, string tag, T value){
//        ES3.Save<T>(tag, value, filename.ToString());
//    }

    public static T LoadOrDefault<T>(StorageFilename filename, string tag, T defaultValue){
        return ES3.Load<T>(tag, filename.ToString(), defaultValue);
    }
    public static T Load<T>(StorageFilename filename, string tag){
        return ES3.Load<T>(tag, filename.ToString());
    }

    public static bool Exists(StorageFilename filename, string tag){
        return ES3.FileExists(filename.ToString()) && ES3.KeyExists(tag, filename.ToString());
    }
    
//    public static void Remove(StorageFilename filename, string tag){
//        if(!Exists(filename, tag)) return ;
//        ES3.DeleteKey(tag, filename.ToString());
//    }


//    public static void SaveAndBackup(StorageFilename filename, string tag, string value){
//        ES3.Save<string>(tag, value, filename.ToString());
//        string key = string.Format("{0}?tag={1}", filename.ToString(), tag);
//        PlayerPrefs.SetString(key, value);
//        PlayerPrefs.Save();
//    }

    public static bool ExistsBackup(StorageFilename filename, string tag){
        string key = string.Format("{0}?tag={1}", filename.ToString(), tag);
        return PlayerPrefs.HasKey(key);
    }

    public static string LoadBackup(StorageFilename filename, string tag){
        string key = string.Format("{0}?tag={1}", filename.ToString(), tag);
        return PlayerPrefs.GetString(key);
    }

    public static void IsDiskFull(Exception ex, Func<string> getDiskFullMessage){
        const int ERROR_HANDLE_DISK_FULL = 0x27;
        const int ERROR_DISK_FULL = 0x70;

        int errorCode = Marshal.GetHRForException(ex) & 0xFFFF;
        if(errorCode == ERROR_HANDLE_DISK_FULL || errorCode == ERROR_DISK_FULL){
            NativeUtils.ShowAlert(ex.Message, getDiskFullMessage());
        }else{
            throw ex;
        }
    }

    public static string LoadRawString(StorageFilename filename){
        return ES3.LoadRawString(filename.ToString());
    }
    public static void SaveRawString(StorageFilename filename, string str){
        ES3.SaveRaw(str, filename.ToString());
    }
}
#endif
