Esempio n. 1
0
    private void CompleteLoadHandler(BaseAbstracResourceLoader loader)
    {
        ByteLoader byteLoader = loader as ByteLoader;

        if (byteLoader.IsError == false)
        {
            Debug.Log(Encoding.UTF8.GetString(byteLoader.ResultObj as byte[]));
        }
    }
Esempio n. 2
0
        public void CreateFile(string fileName, string parent, string inFilePath)
        {
            if (!File.Exists(inFilePath))
            {
                return;
            }

            var pId = GetDirectoryId(PathSplitter.SplitPath(parent));

            if (jsonStructureManager.ExistedFile(pId, fileName))
            {
                return;
            }

            var mimeType = MimeType.MimeTypeMap.GetMimeType(inFilePath);

            using (var stream = new FileStream(inFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                string hash = string.Empty;
                if (jsonStructureManager.IsCheckHash)
                {
                    hash = Crypto.Sha256.GetSha256(stream);
                }

                if (stream.Length > fManager.SplitSize)
                {
                    var(nextId, parentId) = ResolveTermParameters(fileName, parent);
                    var start = fManager.Write(stream, (writeStream) => {
                        while (true)
                        {
                            byte[] bs    = new byte[fManager.SplitSize];
                            int readSize = stream.Read(bs, 0, bs.Length);
                            if (readSize == 0)
                            {
                                break;
                            }
                            writeStream.Write(bs, 0, readSize);
                        }
                    }, LEN);
                    jsonStructureManager.CreateFile(nextId, parentId, fileName, start, hash, new Dictionary <string, string> {
                        { "MimeType", mimeType }
                    });
                }
                else
                {
                    var data = ByteLoader.FromFile(stream);
                    if (data != null)
                    {
                        CreateFile(fileName, parent, data, mimeType, hash);
                    }
                }
            }
        }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ByteLoader.LoadAsset(url, m_LoadAssetModel, CompleteLoadHandler);
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            // OnApplicationQuit();
        }
    }
Esempio n. 4
0
 private void OnApplicationQuit()
 {
     Debug.Log("OnApplicationQuit");
     ByteLoader.UnLoadAsset(url);
 }