Exemplo n.º 1
0
        public static void Save <T>(T data, params string[] subPaths)
        {
            string fileName      = ProtoStorage.GetFileName(subPaths);
            string fileDataPath  = ProtoStorage.GetFileDataPath(fileName);
            string directoryName = Path.GetDirectoryName(fileDataPath);

            try
            {
                if (directoryName != null && !Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }
                using (FileStream fileStream = File.Open(fileDataPath, FileMode.Create))
                {
                    Serializer.Serialize <T>(fileStream, data);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Interface.Oxide.LogException(string.Concat("Failed to save protobuf data to ", fileName), exception);
            }
        }
Exemplo n.º 2
0
        public static T Load <T>(params string[] subPaths)
        {
            T      t;
            string fileName     = ProtoStorage.GetFileName(subPaths);
            string fileDataPath = ProtoStorage.GetFileDataPath(fileName);

            try
            {
                if (File.Exists(fileDataPath))
                {
                    using (FileStream fileStream = File.OpenRead(fileDataPath))
                    {
                        t = Serializer.Deserialize <T>(fileStream);
                    }
                    return(t);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Interface.Oxide.LogException(string.Concat("Failed to load protobuf data from ", fileName), exception);
            }
            return(default(T));
        }
Exemplo n.º 3
0
 public static bool Exists(params string[] subPaths)
 {
     return(File.Exists(ProtoStorage.GetFileDataPath(ProtoStorage.GetFileName(subPaths))));
 }