예제 #1
0
        public Texture2D GetItemImage(string name)
        {
            using (LiteFileStream stream = _DB.FileStorage.OpenRead(name))
            {
                //Debug.Log("GetItemImage:");
                //Debug.Log(stream.FileInfo.Metadata.Get("width").AsInt32);
                //Debug.Log(stream.FileInfo.Metadata.Get("height").AsInt32);
                //Debug.Log((TextureFormat)stream.FileInfo.Metadata.Get("format").AsInt32);
                //Debug.Log(stream.Length);

                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length - 1);
                //Texture2D image = new Texture2D(
                //    stream.FileInfo.Metadata.Get("width").AsInt32,
                //    stream.FileInfo.Metadata.Get("height").AsInt32,
                //    (TextureFormat)stream.FileInfo.Metadata.Get("format").AsInt32,
                //    stream.FileInfo.Metadata.Get("mipmap").AsBoolean
                //    );

                //image.LoadRawTextureData(buffer);
                //image.Apply();

                Texture2D image = new Texture2D(0, 0);
                bool      f**k  = image.LoadImage(buffer);
                //Debug.Log(f**k);

                //Debug.Log(image.width);
                //Debug.Log(image.height);
                //Debug.Log(image.format);
                //Debug.Log("===========");

                return(image);
            }
        }
예제 #2
0
 public byte[] StreamToBytes(LiteFileStream stream)
 {
     byte[] bytes = new byte[stream.Length];
     stream.Read(bytes, 0, bytes.Length);
     return(bytes);
 }
예제 #3
0
        /// <inheritdoc/>
        public void ForkStateReferences <T>(
            string srcNamespace,
            string destNamespace,
            Block <T> branchPoint,
            IImmutableSet <Address> addressesToStrip)
            where T : IAction, new()
        {
            long branchPointIndex     = branchPoint.Index;
            List <LiteFileInfo> files =
                _db.FileStorage
                .Find($"{StateRefIdPrefix}{srcNamespace}")
                .ToList();

            if (!files.Any() && addressesToStrip.Any())
            {
                throw new NamespaceNotFoundException(
                          srcNamespace,
                          "The source namespace to be forked does not exist.");
            }

            foreach (LiteFileInfo srcFile in files)
            {
                string destId =
                    $"{StateRefIdPrefix}{destNamespace}/{srcFile.Filename}";
                _db.FileStorage.Upload(
                    destId,
                    srcFile.Filename,
                    new MemoryStream());

                LiteFileInfo destFile = _db.FileStorage.FindById(destId);
                using (LiteFileStream srcStream = srcFile.OpenRead())
                    using (LiteFileStream destStream = destFile.OpenWrite())
                    {
                        while (srcStream.Position < srcStream.Length)
                        {
                            var hashBytes  = new byte[HashDigest <SHA256> .Size];
                            var indexBytes = new byte[sizeof(long)];

                            srcStream.Read(hashBytes, 0, hashBytes.Length);
                            srcStream.Read(indexBytes, 0, indexBytes.Length);

                            long currentIndex =
                                BitConverter.ToInt64(indexBytes, 0);

                            if (currentIndex <= branchPointIndex)
                            {
                                destStream.Write(hashBytes, 0, hashBytes.Length);
                                destStream.Write(indexBytes, 0, indexBytes.Length);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                if (destFile.Length == 0)
                {
                    _db.FileStorage.Delete(destId);
                }
            }
        }