예제 #1
0
        public override IFolderObject Restore(byte[] data, bool forName = false)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                BinaryReader r = new BinaryReader(ms, Encoding.Default);

                if (r.ReadInt32() == 0) // key item
                {
                    string path = r.ReadString();
                    //Debug.WriteLine("KEY: "+path);
                    FolderAttributes attrs = (FolderAttributes)r.ReadInt32();

                    if (attrs != FolderAttributes.None)
                    {
                        int        nDataLen = r.ReadInt32();
                        byte[]     btFo     = r.ReadBytes(nDataLen);
                        FileObject fo       = FileObject.ToObject(btFo);

                        //Folder.ItemsIcons = ItemsIcons;

                        Folder folder = new Folder(PathData, idListAbsolute, "", path, attrs, fo, ShellView, this);
                        if (ItemsIcons.ContainsKey("folder"))
                        {
                            folder.Icons = ItemsIcons["folder"];
                        }
                        return(folder);
                    }
                    else
                    {
                        Folder folder = new Folder(PathData, idListAbsolute, "", path, attrs, null, ShellView, this);
                        if (ItemsIcons.ContainsKey("folder"))
                        {
                            folder.Icons = ItemsIcons["folder"];
                        }
                        return(folder);
                    }
                }
                else                                    // value item
                {
                    int        nDataLen = r.ReadInt32();
                    byte[]     btFo     = r.ReadBytes(nDataLen);
                    FileObject fo       = FileObject.ToObject(btFo);

                    string path      = null;
                    string valueName = string.Empty;
                    try
                    {
                        // Debug.WriteLine("Value: " + data);
                        if (r.BaseStream.Position < r.BaseStream.Length)
                        {
                            path = r.ReadBoolean() ? r.ReadString() : null;
                        }
                        if (r.BaseStream.Position < r.BaseStream.Length)
                        {
                            valueName = r.ReadString();
                        }
                    }
                    catch (Exception)
                    {
                    }

                    Item it = new Item(PathData, "", path, valueName, fo, this, ShellView);

                    string ext = IconHelper.GetExtension(valueName);
                    if (string.IsNullOrEmpty(ext) && ItemsIcons.ContainsKey("no"))
                    {
                        it.Icons = ItemsIcons["no"];
                    }

                    if (!string.IsNullOrEmpty(ext) && ItemsIcons.ContainsKey(ext))
                    {
                        it.Icons = ItemsIcons[ext];
                    }

                    return(it);
                }
            }


            if (items == null)
            {
                items = GetItems(null) as ArrayList;
            }
            //return new Item(PathData, BitConverter.ToInt32(data, 0), BitConverter.ToInt32(data, 0).ToString());
            //Item it = (Item)(items[BitConverter.ToInt32(data, 0)]);
            //it.SetPath(PathData);
            try
            {
                return((IFolderObject)items[BitConverter.ToInt32(data, 0)]);
            }
            catch (Exception)
            {
                return(this);
            }
        }