Beispiel #1
0
        public static void DatafileToProto <T>(string name, bool deleteAfter = true)
        {
            var dfs = Interface.Oxide.DataFileSystem;

            if (!dfs.ExistsDatafile(name))
            {
                return;
            }
            if (ProtoStorage.Exists(name))
            {
                Interface.Oxide.LogWarning("Failed to import JSON file: {0} already exists.", name);
                return;
            }
            try
            {
                var data = dfs.ReadObject <T>(name);
                ProtoStorage.Save(data, name);
                if (deleteAfter)
                {
                    File.Delete(dfs.GetFile(name).Filename);
                }
            }
            catch (Exception ex)
            {
                Interface.Oxide.LogException("Failed to convert datafile to proto storage: " + name, ex);
            }
        }
        public static void DatafileToProto <T>(string name, bool deleteAfter = true)
        {
            DataFileSystem dataFileSystem = Interface.Oxide.DataFileSystem;

            if (!dataFileSystem.ExistsDatafile(name))
            {
                return;
            }
            if (ProtoStorage.Exists(new string[] { name }))
            {
                Interface.Oxide.LogWarning("Failed to import JSON file: {0} already exists.", new object[] { name });
                return;
            }
            try
            {
                ProtoStorage.Save <T>(dataFileSystem.ReadObject <T>(name), new string[] { name });
                if (deleteAfter)
                {
                    File.Delete(dataFileSystem.GetFile(name).Filename);
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Interface.Oxide.LogException(string.Concat("Failed to convert datafile to proto storage: ", name), exception);
            }
        }
Beispiel #3
0
        public static IEnumerable <string> GetFiles(string subDirectory)
        {
            string fileDataPath = ProtoStorage.GetFileDataPath(subDirectory.Replace("..", ""));

            if (!Directory.Exists(fileDataPath))
            {
                yield break;
            }
            string[] files = Directory.GetFiles(fileDataPath, "*.data");
            for (int i = 0; i < (int)files.Length; i++)
            {
                yield return(Utility.GetFileNameWithoutExtension(files[i]));
            }
            files = null;
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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));
        }
Beispiel #6
0
 public static bool Exists(params string[] subPaths)
 {
     return(File.Exists(ProtoStorage.GetFileDataPath(ProtoStorage.GetFileName(subPaths))));
 }