Пример #1
0
        public bool LoadAssetFile(BaseAsset asset)
        {
            string path   = NativeFSWorker.GetAssetPath(asset);
            bool   result = true;

            try {
                using (FileStream stream = new FileStream(path, FileMode.Open))
                    using (BinaryReader reader = new BinaryReader(stream)) {
                        /*int len = (int)reader.BaseStream.Length;
                         * byte[] encrypted = reader.ReadBytes(len);
                         *
                         * using (var inStream = new MemoryStream(encrypted))
                         * using (GZipStream gzip = new GZipStream(inStream, CompressionMode.Decompress))
                         * using (var outStream = new MemoryStream()) {
                         *  gzip.CopyTo(outStream);
                         *  using (BinaryReader decompressReader = new BinaryReader(outStream)) {
                         *      var test = outStream.ToArray();
                         *      decompressReader.BaseStream.Position = 0;
                         *      result = asset.LoadAsset(decompressReader);
                         *  }
                         * }*/
                        result = asset.LoadAsset(reader);
                    }
            } catch (Exception ex) {
                Console.WriteLine("Load file error: {0}", ex.Message);
                asset.Type = AssetTypes.Invalid;
                result     = false;
            }
            return(result);
        }
Пример #2
0
        private bool CreateAssetTypeDirectory(AssetTypes type)
        {
            string path = NativeFSWorker.GetAssetTypePath(type);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                Console.WriteLine("Create directory: {0}", path);
            }
            return(true);
        }
Пример #3
0
        public bool CreateAssetFile(BaseAsset asset, bool rewrite)
        {
            CreateAssetFilesTree();
            if (asset.Type == AssetTypes.Shader)
            {
                Console.WriteLine("Create asset: {0} type: {1} {2}", asset.Name,
                                  ((ShaderAsset)asset).ShaderType.ToString(), asset.Type.ToString());
            }
            else
            {
                Console.WriteLine("Create asset: {0} type: {1}", asset.Name, asset.Type.ToString());
            }

            string path = NativeFSWorker.GetAssetPath(asset);

            if (!rewrite)
            {
                string actualName = asset.Name;
                int    postfix    = 0;
                while (File.Exists(path))
                {
                    actualName = asset.Name + "_" + (++postfix);
                    path       = NativeFSWorker.GetAssetPath(asset, actualName);
                }
                asset.Name = actualName;
            }

            using (FileStream stream = new FileStream(path, FileMode.Create))
                using (BinaryWriter writer = new BinaryWriter(stream)) {
                    /*using (MemoryStream ms = new MemoryStream()) {
                     *  using (GZipStream compressStream = new GZipStream(ms, CompressionMode.Compress))
                     *  using (BinaryWriter compressWriter = new BinaryWriter(compressStream)) {
                     *      asset.SaveAsset(compressWriter);
                     *      //compressWriter.Close();
                     *  }
                     *  writer.Write(ms.ToArray());
                     * }*/
                    asset.SaveAsset(writer);
                }
            return(true);
        }