Exemplo n.º 1
0
        //public void SaveProjectData(string name, ProjectData data, ProjectEventHandler callback)
        //{
        //    m_storage.SaveFile(name + ".rtpdata", m_serializer.Serialize(data), saveDataCompleted =>
        //    {
        //        if (callback != null)
        //        {
        //            callback(new ProjectPayload());
        //        }
        //    });
        //}

        //public void Load(ProjectItem folder, ProjectEventHandler<ProjectItem[]> callback, params int[] exceptTypes)
        //{
        //    string folderPath = folder.ToString();
        //    m_storage.GetFiles(folderPath, getFilesResult =>
        //    {
        //        string[] path = getFilesResult.Data.Where(filePath => filePath.EndsWith("." + FileMetaExt)).ToArray();
        //        Array.Resize(ref path, path.Length + path.Length);
        //        for (int i = path.Length; i < path.Length + path.Length; ++i)
        //        {
        //            path[path.Length + i] = path[i];
        //            path[i] = path[i].Remove(path[i].LastIndexOf("." + FileMetaExt));
        //        }

        //        HashSet<int> exceptTypesHs = null;
        //        if(exceptTypes != null && exceptTypes.Length > 0)
        //        {
        //            exceptTypesHs = new HashSet<int>();
        //            for(int i = 0; i < exceptTypes.Length; ++i)
        //            {
        //                if(!exceptTypesHs.Contains(exceptTypes[i]))
        //                {
        //                    exceptTypesHs.Add(exceptTypes[i]);
        //                }
        //            }
        //        }
        //        m_storage.LoadFiles(path, loadFilesResult =>
        //        {
        //            List<ProjectItem> loadedItems = new List<ProjectItem>();
        //            for (int i = 0; i < path.Length; ++i)
        //            {
        //                byte[] dataRaw = loadFilesResult.Data[i];
        //                byte[] metaRaw = loadFilesResult.Data[path.Length + i];
        //                if (dataRaw != null && metaRaw != null)
        //                {
        //                    ProjectItemMeta meta = m_serializer.Deserialize<ProjectItemMeta>(metaRaw);
        //                    bool loadData = exceptTypesHs == null || !exceptTypesHs.Contains(meta.Type);

        //                    ProjectItemData data = loadData ? m_serializer.Deserialize<ProjectItemData>(dataRaw) : null;
        //                    loadedItems.Add(new ProjectItem(meta, data) { Parent = folder });
        //                }
        //            }
        //            callback(new ProjectPayload<ProjectItem[]>(loadedItems.ToArray()));
        //        });
        //    });
        //}

        public void Load(string[] path, ProjectEventHandler <ProjectItem[]> callback, params int[] exceptTypes)
        {
            int pathLength = path.Length;

            Array.Resize(ref path, pathLength + pathLength);
            for (int i = 0; i < pathLength; ++i)
            {
                path[pathLength + i] = path[i] + "." + FileMetaExt;
            }

            HashSet <int> exceptTypesHs = null;

            if (exceptTypes != null && exceptTypes.Length > 0)
            {
                exceptTypesHs = new HashSet <int>();
                for (int i = 0; i < exceptTypes.Length; ++i)
                {
                    if (!exceptTypesHs.Contains(exceptTypes[i]))
                    {
                        exceptTypesHs.Add(exceptTypes[i]);
                    }
                }
            }

            m_storage.LoadFiles(path, loadFilesResult =>
            {
                List <ProjectItem> loadedItems = new List <ProjectItem>();
                for (int i = 0; i < pathLength; ++i)
                {
                    byte[] dataRaw = loadFilesResult.Data[i];
                    byte[] metaRaw = loadFilesResult.Data[pathLength + i];
                    if (dataRaw != null && metaRaw != null)
                    {
                        ProjectItemMeta meta = m_serializer.Deserialize <ProjectItemMeta>(metaRaw);
                        bool loadData        = exceptTypesHs == null || !exceptTypesHs.Contains(meta.TypeCode);

                        ProjectItemData data = loadData ? m_serializer.Deserialize <ProjectItemData>(dataRaw) : null;
                        loadedItems.Add(new ProjectItem(meta, data));
                    }
                }
                callback(new ProjectPayload <ProjectItem[]>(loadedItems.ToArray()));
            });
        }
Exemplo n.º 2
0
        public void Rename(ProjectItem item, string name, ProjectEventHandler callback)
        {
            string srcPath = item.ToString();
            string srcName = item.Name;

            item.Name = ProjectItem.GetUniqueName(name, item, item.Parent);
            string dstPath = item.ToString();

            if (!item.IsFolder && !item.IsScene)
            {
                m_storage.LoadFile(srcPath, loadFilesResult =>
                {
                    byte[] dataRaw = loadFilesResult.Data;
                    if (dataRaw != null)
                    {
                        ProjectItemData data = m_serializer.Deserialize <ProjectItemData>(dataRaw);
                        item.Internal_Data   = data;
                        item.Rename(name);
                    }

                    Save(item, srcPath, false, saveCompleted =>
                    {
                        UnloadData(item);
                        Move(item, callback, srcPath, dstPath);
                    });
                });
            }
            else
            {
                if (!item.IsFolder)
                {
                    Save(item, srcPath, true, saveCompleted =>
                    {
                        Move(item, callback, srcPath, dstPath);
                    });
                }
                else
                {
                    Move(item, callback, srcPath, dstPath);
                }
            }
        }
Exemplo n.º 3
0
        public void LoadData(ProjectItem[] items, ProjectEventHandler <ProjectItem[]> callback, params int[] exceptTypes)
        {
            HashSet <int> exceptTypesHs = null;

            if (exceptTypes != null && exceptTypes.Length > 0)
            {
                exceptTypesHs = new HashSet <int>();
                for (int i = 0; i < exceptTypes.Length; ++i)
                {
                    if (!exceptTypesHs.Contains(exceptTypes[i]))
                    {
                        exceptTypesHs.Add(exceptTypes[i]);
                    }
                }
            }

            if (exceptTypes != null)
            {
                items = items.Where(item => !exceptTypes.Contains(item.TypeCode)).ToArray();
            }

            string[] path = items.Select(item => item.ToString()).ToArray();
            m_storage.LoadFiles(path, loadFilesResult =>
            {
                for (int i = 0; i < path.Length; ++i)
                {
                    byte[] dataRaw = loadFilesResult.Data[i];
                    if (dataRaw != null)
                    {
                        ProjectItemData data   = m_serializer.Deserialize <ProjectItemData>(dataRaw);
                        items[i].Internal_Data = data;
                    }
                }
                callback(new ProjectPayload <ProjectItem[]>(items));
            });
        }
Exemplo n.º 4
0
 public ProjectItem(ProjectItemMeta meta, ProjectItemData data)
 {
     Internal_Meta = meta;
     Internal_Data = data;
 }
Exemplo n.º 5
0
        private void LoadFiles(ProjectItem item, ProjectEventHandler callback, bool metaOnly = true, HashSet <int> exceptTypesHS = null)
        {
            ProjectItem[] folders = item.Children != null?item.Children.Where(c => c.IsFolder).ToArray() : new ProjectItem[0];

            Action <ProjectEventHandler>[] loadFilesActions = new Action <ProjectEventHandler> [folders.Length];
            for (int i = 0; i < folders.Length; ++i)
            {
                ProjectItem childItem = folders[i];
                loadFilesActions[i] = cb => LoadFiles(childItem, cb, metaOnly, exceptTypesHS);
            }

            m_storage.GetFiles(item.ToString(), getFilesCompleted =>
            {
                string[] path = getFilesCompleted.Data;

                if (path == null && path.Length > 0)
                {
                    Parallel(loadFilesActions, parallelCallback =>
                    {
                        if (callback != null)
                        {
                            callback(new ProjectPayload());
                        }
                    });
                }
                else
                {
                    int metaLength;
                    if (metaOnly)
                    {
                        path       = path.Where(n => n.EndsWith("." + FileMetaExt)).ToArray();
                        metaLength = path.Length;
                    }
                    else
                    {
                        path       = path.Where(n => n.EndsWith("." + FileMetaExt)).ToArray();
                        metaLength = path.Length;
                        Array.Resize(ref path, metaLength + metaLength);
                        for (int i = 0; i < metaLength; ++i)
                        {
                            path[metaLength + i] = path[i].Remove(path[i].LastIndexOf("." + FileMetaExt));
                        }
                    }

                    if (metaLength > 0)
                    {
                        m_storage.LoadFiles(path, loadFilesCompleted =>
                        {
                            if (item.Children == null)
                            {
                                item.Children = new List <ProjectItem>();
                            }

                            for (int i = 0; i < metaLength; ++i)
                            {
                                ProjectItemMeta meta = null;
                                ProjectItemData data = null;

                                byte[] metaRaw = loadFilesCompleted.Data[i];
                                if (metaRaw != null)
                                {
                                    meta = m_serializer.Deserialize <ProjectItemMeta>(metaRaw);
                                }

                                if (!metaOnly)
                                {
                                    bool loadData = meta != null && (exceptTypesHS == null || !exceptTypesHS.Contains(meta.TypeCode));
                                    if (loadData)
                                    {
                                        byte[] dataRaw = loadFilesCompleted.Data[metaLength + i];
                                        if (dataRaw != null)
                                        {
                                            data = m_serializer.Deserialize <ProjectItemData>(dataRaw);
                                        }
                                    }
                                }

                                if (meta.TypeCode == ProjectItemTypes.Folder)
                                {
                                    ProjectItem folder = item.Children.Where(c => c.IsFolder && c.NameExt == meta.Name).FirstOrDefault();
                                    if (folder != null)
                                    {
                                        folder.Internal_Meta = meta;
                                    }
                                }
                                else
                                {
                                    ProjectItem childItem = new ProjectItem(meta, data);
                                    item.AddChild(childItem);
                                }
                            }

                            Parallel(loadFilesActions, parallelCallback =>
                            {
                                if (callback != null)
                                {
                                    callback(new ProjectPayload());
                                }
                            });
                        });
                    }
                    else
                    {
                        Parallel(loadFilesActions, parallelCallback =>
                        {
                            if (callback != null)
                            {
                                callback(new ProjectPayload());
                            }
                        });
                    }
                }
            });
        }