Exemple #1
0
        public static void SaveString(string resName, string resPath, string saveData, string password, C_ISaveEncoder encoder, Encoding encoding)
        {
            if (string.IsNullOrEmpty(resName) || string.IsNullOrEmpty(saveData))
            {
                Debug.LogError("C_Save SaveString Param Error!! resName = " + resName + ", resPath = " + resPath);
                return;
            }

            SaveByte(resName, resPath, encoding.GetBytes(saveData), password, encoder);
        }
Exemple #2
0
        public static void Save <T>(string resName, string resPath, T obj, C_EnumSaveSerializer enumSerializer, C_ISaveEncoder encoder, Encoding encoding)
        {
            if (string.IsNullOrEmpty(resName) || obj == null || encoder == null || encoding == null)
            {
                Debug.LogError("C_Save Save Param Error!! resName = " + resName + ", resPath = " + resPath);
                return;
            }

            byte[] bytes = ConvertByte <T>(obj, enumSerializer);

            SaveByte(resName, resPath, bytes, "", encoder);
        }
Exemple #3
0
        public static byte[] LoadByte(string resName, string resPath, string password, C_ISaveEncoder encoder, Encoding encoding)
        {
            if (string.IsNullOrEmpty(resName) || encoder == null || encoding == null)
            {
                if (Application.isPlaying)
                {
                    Debug.LogError("C_Save LoadByte Param Error!! resName = " + resName + ", resPath = " + resPath);
                }
                return(null);
            }

            string filePath = resPath + resName;

            //Debug.Log("C_Save Load filePath = " + filePath);

            byte[] data = null;

            if (filePath.Contains("://"))
            {
                using (UnityWebRequest request = UnityWebRequest.Get(filePath))
                {
                    request.SendWebRequest();

                    while (!request.isDone)
                    {
                        if (request.isNetworkError)
                        {
                            Debug.LogWarning("C_Save LoadByte file is null!! filePath = " + filePath + ", request.isError" + request.isNetworkError);
                            return(data);
                        }
                    }

                    if (request.isNetworkError)
                    {
                        Debug.LogWarning("C_Save LoadByte file is null!! filePath = " + filePath + ", request.isError" + request.isNetworkError);
                    }
                    else
                    {
                        data = request.downloadHandler.data;
                    }
                }
            }
            else
            {
                if (!File.Exists(filePath))
                {
                    Debug.LogWarning("C_Save LoadByte file is null!! filePath = " + filePath);
                }
                else
                {
                    data = File.ReadAllBytes(filePath);
                }
            }

            if (data != null && !string.IsNullOrEmpty(password))
            {
                data = encoder.Decode(data, password);
            }

            return(data);
        }
Exemple #4
0
        public static string LoadString(string resName, string resPath, string password, C_ISaveEncoder encoder, Encoding encoding)
        {
            byte[] data = LoadByte(resName, resPath, password, encoder, encoding);
            if (data != null)
            {
                return(encoding.GetString(data));
            }

            return("");
        }
Exemple #5
0
        public static T Load <T>(string resName, byte[] resData, T defaultValue, C_EnumSaveSerializer enumSerializer, C_ISaveEncoder encoder, Encoding encoding)
        {
            if (resData == null)
            {
                return(defaultValue);
            }

            Stream stream = new MemoryStream(resData, true);

            C_ISaveSerializer serializer = GetSaveSerializer(enumSerializer);

            T result = serializer.Deserialize <T>(stream, encoding);

            stream.Close();

            return(result);
        }
Exemple #6
0
        public static void SaveByte(string resName, string resPath, byte[] saveData, string password, C_ISaveEncoder encoder)
        {
            if (saveData == null || saveData.Length <= 0)
            {
                Debug.LogError("C_Save Save saveData is Null or Empty!! resName = " + resName + ", resPath = " + resPath);
                return;
            }

            string filePath = resPath + resName;

            Debug.Log("C_Save Save filePath = " + filePath);

            Stream stream = new MemoryStream();

            if (!string.IsNullOrEmpty(password))
            {
                saveData = encoder.Encode(saveData, password);
            }

            if (!Directory.Exists(resPath))
            {
                Directory.CreateDirectory(resPath);
            }

            FileStream   fs = new FileStream(filePath, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(saveData);
            bw.Close();
            fs.Close();
            stream.Close();
        }