예제 #1
0
        public void ExportProject(string projectPath, string targetPath, StorageEventHandler callback)
        {
            QueueUserWorkItem(() =>
            {
                try
                {
                    string projectFullPath = FullPath(projectPath);

                    FastZip fastZip          = new FastZip();
                    fastZip.CompressionLevel = Deflater.CompressionLevel.NO_COMPRESSION;
                    fastZip.CreateZip(targetPath, projectFullPath, true, null);

                    Callback(() =>
                    {
                        callback(new Error(Error.OK));
                    });
                }
                catch (Exception e)
                {
                    Callback(() =>
                    {
                        callback(new Error(Error.E_Exception)
                        {
                            ErrorText = e.ToString()
                        });
                    });
                }
            });
        }
예제 #2
0
        public void GetProject(string projectPath, StorageEventHandler <ProjectInfo> callback)
        {
            projectPath = Path.Combine(FullPath(projectPath), "Project.rtmeta");
            ProjectInfo projectInfo;
            Error       error      = new Error();
            ISerializer serializer = RTSL2Deps.Get.Serializer;

            if (!File.Exists(projectPath))
            {
                projectInfo = new ProjectInfo();
            }
            else
            {
                try
                {
                    using (FileStream fs = File.OpenRead(projectPath))
                    {
                        projectInfo = serializer.Deserialize <ProjectInfo>(fs);
                    }
                }
                catch (Exception e)
                {
                    projectInfo     = new ProjectInfo();
                    error.ErrorCode = Error.E_Exception;
                    error.ErrorText = e.ToString();
                }
            }
            callback(error, projectInfo);
        }
예제 #3
0
        public void CreateProject(string projectName, StorageEventHandler <ProjectInfo> callback)
        {
            string projectDir = FullPath(projectName);

            if (Directory.Exists(projectDir))
            {
                Error error = new Error(Error.E_AlreadyExist);
                error.ErrorText = "Project with the same name already exists " + projectName;
                callback(error, null);
            }
            else
            {
                ISerializer serializer = IOC.Resolve <ISerializer>();
                Directory.CreateDirectory(projectDir);
                ProjectInfo projectInfo = null;
                using (FileStream fs = File.OpenWrite(projectDir + "/Project.rtmeta"))
                {
                    projectInfo = new ProjectInfo
                    {
                        Name          = projectName,
                        LastWriteTime = DateTime.UtcNow
                    };

                    serializer.Serialize(projectInfo, fs);
                }
                callback(new Error(Error.OK), projectInfo);
            }
        }
예제 #4
0
        public void Delete(string projectPath, string[] paths, StorageEventHandler callback)
        {
            string fullPath = FullPath(projectPath);

            for (int i = 0; i < paths.Length; ++i)
            {
                string path = fullPath + paths[i];
                if (File.Exists(path))
                {
                    File.Delete(path);
                    if (File.Exists(path + MetaExt))
                    {
                        File.Delete(path + MetaExt);
                    }
                    if (File.Exists(path + PreviewExt))
                    {
                        File.Delete(path + PreviewExt);
                    }
                }
                else if (Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
            }

            callback(new Error(Error.OK));
        }
예제 #5
0
        public void GetProjects(StorageEventHandler <ProjectInfo[]> callback)
        {
            string projectsRoot = FullPath(string.Empty);

            string[]           projectDirs = Directory.GetDirectories(projectsRoot);
            List <ProjectInfo> result      = new List <ProjectInfo>();
            ISerializer        serializer  = IOC.Resolve <ISerializer>();

            for (int i = 0; i < projectDirs.Length; ++i)
            {
                string projectDir = projectDirs[i];
                if (File.Exists(projectDir + "/Project.rtmeta"))
                {
                    ProjectInfo projectInfo;
                    using (FileStream fs = File.OpenRead(projectDir + "/Project.rtmeta"))
                    {
                        projectInfo = serializer.Deserialize <ProjectInfo>(fs);
                    }
                    projectInfo.Name          = Path.GetFileName(projectDir);
                    projectInfo.LastWriteTime = File.GetLastWriteTimeUtc(projectDir + "/Project.rtmeta");
                    result.Add(projectInfo);
                }
            }
            callback(new Error(Error.OK), result.ToArray());
        }
예제 #6
0
        public void Load(string projectPath, string bundleName, StorageEventHandler <AssetBundleInfo> callback)
        {
            QueueUserWorkItem(() =>
            {
                string assetBundleInfoPath = bundleName.Replace("/", "_").Replace("\\", "_");
                assetBundleInfoPath       += ".rtbundle";
                assetBundleInfoPath        = FullPath(projectPath) + "/" + assetBundleInfoPath;

                ISerializer serializer = IOC.Resolve <ISerializer>();
                if (File.Exists(assetBundleInfoPath))
                {
                    AssetBundleInfo result = null;
                    using (FileStream fs = File.OpenRead(assetBundleInfoPath))
                    {
                        result = serializer.Deserialize <AssetBundleInfo>(fs);
                    }

                    Callback(() => callback(new Error(Error.OK), result));
                }
                else
                {
                    Callback(() => callback(new Error(Error.E_NotFound), null));
                }
            });
        }
예제 #7
0
        public void DeleteProject(string projectPath, StorageEventHandler callback)
        {
            string projectDir = FullPath(projectPath);

            Directory.Delete(projectDir, true);
            callback(new Error(Error.OK));
        }
예제 #8
0
        public void GetValues(string projectPath, string searchPattern, Type type, StorageEventHandler <PersistentObject[]> callback)
        {
            QueueUserWorkItem(() =>
            {
                string fullPath = FullPath(projectPath);
                string path     = fullPath + "/" + KeyValueStorage;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string[] files            = Directory.GetFiles(path, searchPattern);
                PersistentObject[] result = new PersistentObject[files.Length];

                ISerializer serializer = IOC.Resolve <ISerializer>();
                for (int i = 0; i < files.Length; ++i)
                {
                    using (FileStream fs = File.OpenRead(files[i]))
                    {
                        result[i] = (PersistentObject)serializer.Deserialize(fs, type);
                    }
                }

                Callback(() => callback(Error.NoError, result));
            });
        }
예제 #9
0
        public void GetValue(string projectPath, string key, Type type, StorageEventHandler <PersistentObject> callback)
        {
            string fullPath = FullPath(projectPath);
            string path     = fullPath + "/" + KeyValueStorage;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = path + "/" + key;
            if (File.Exists(path))
            {
                ISerializer serializer = IOC.Resolve <ISerializer>();
                object      result     = null;
                using (FileStream fs = File.OpenRead(path))
                {
                    result = serializer.Deserialize(fs, type);
                }

                callback(new Error(Error.OK), (PersistentObject)result);
            }
            else
            {
                callback(new Error(Error.E_NotFound), null);
                return;
            }
        }
예제 #10
0
        public void GetPreviews(string projectPath, string[] folderPath, StorageEventHandler <Preview[][]> callback)
        {
            projectPath = AssetsFolderPath(projectPath);

            ISerializer serializer = RTSL2Deps.Get.Serializer;

            Preview[][] result = new Preview[folderPath.Length][];
            for (int i = 0; i < folderPath.Length; ++i)
            {
                string path = Path.Combine(projectPath, folderPath[i]);
                if (!Directory.Exists(path))
                {
                    continue;
                }

                string[]  files    = Directory.GetFiles(path, "*" + PreviewExt);
                Preview[] previews = new Preview[files.Length];
                for (int j = 0; j < files.Length; ++j)
                {
                    previews[j] = Load <Preview>(serializer, files[j]);
                }

                result[i] = previews;
            }

            callback(new Error(), result);
        }
예제 #11
0
        public void DeleteValue(string projectPath, string key, StorageEventHandler callback)
        {
            string fullPath = FullPath(projectPath);
            string path     = fullPath + "/" + KeyValueStorage + "/" + key;

            File.Delete(path);
            callback(Error.NoError);
        }
예제 #12
0
        public void Load(string projectPath, string[] assetPaths, Type[] types, StorageEventHandler <PersistentObject[]> callback)
        {
            QueueUserWorkItem(() =>
            {
                PersistentObject[] result = new PersistentObject[assetPaths.Length];
                for (int i = 0; i < assetPaths.Length; ++i)
                {
                    string assetPath       = assetPaths[i];
                    assetPath              = FullPath(projectPath) + assetPath;
                    ISerializer serializer = IOC.Resolve <ISerializer>();
                    try
                    {
                        if (File.Exists(assetPath))
                        {
                            if (types[i] == typeof(PersistentRuntimeTextAsset))
                            {
                                PersistentRuntimeTextAsset textAsset = new PersistentRuntimeTextAsset();
                                textAsset.name = Path.GetFileName(assetPath);
                                textAsset.Text = File.ReadAllText(assetPath);
                                textAsset.Ext  = Path.GetExtension(assetPath);
                                result[i]      = textAsset;
                            }
                            else if (types[i] == typeof(PersistentRuntimeBinaryAsset))
                            {
                                PersistentRuntimeBinaryAsset binAsset = new PersistentRuntimeBinaryAsset();
                                binAsset.name = Path.GetFileName(assetPath);
                                binAsset.Data = File.ReadAllBytes(assetPath);
                                binAsset.Ext  = Path.GetExtension(assetPath);
                                result[i]     = binAsset;
                            }
                            else
                            {
                                using (FileStream fs = File.OpenRead(assetPath))
                                {
                                    result[i] = (PersistentObject)serializer.Deserialize(fs, types[i]);
                                }
                            }
                        }
                        else
                        {
                            Callback(() => callback(new Error(Error.E_NotFound), new PersistentObject[0]));
                            return;
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogErrorFormat("Unable to load asset: {0} -> got exception: {1} ", assetPath, e.ToString());
                        Callback(() => callback(new Error(Error.E_Exception)
                        {
                            ErrorText = e.ToString()
                        }, new PersistentObject[0]));
                        return;
                    }
                }

                Callback(() => callback(new Error(Error.OK), result));
            });
        }
예제 #13
0
        public void DeleteFile(string path, StorageEventHandler <string> callback)
        {
            CombineWithBasePath(ref path);

            File.Delete(path);
            if (callback != null)
            {
                callback(new StoragePayload <string>(path));
            }
        }
예제 #14
0
        public void DeleteFolder(string path, StorageEventHandler <string> callback)
        {
            CombineWithBasePath(ref path);

            Directory.Delete(path, true);
            if (callback != null)
            {
                callback(new StoragePayload <string>(path));
            }
        }
예제 #15
0
        public void SaveFile(string path, byte[] data, StorageEventHandler <string> callback)
        {
            CombineWithBasePath(ref path);

            File.WriteAllBytes(path, data);
            if (callback != null)
            {
                callback(new StoragePayload <string>(path));
            }
        }
예제 #16
0
        public void GetProject(string projectName, StorageEventHandler <ProjectInfo, AssetBundleInfo[]> callback)
        {
            string      projectDir  = FullPath(projectName);
            string      projectPath = projectDir + "/Project.rtmeta";
            ProjectInfo projectInfo;
            Error       error      = new Error();
            ISerializer serializer = IOC.Resolve <ISerializer>();

            AssetBundleInfo[] result = new AssetBundleInfo[0];
            if (!File.Exists(projectPath))
            {
                Directory.CreateDirectory(projectDir);
                using (FileStream fs = File.OpenWrite(projectDir + "/Project.rtmeta"))
                {
                    projectInfo = new ProjectInfo
                    {
                        Name          = projectName,
                        LastWriteTime = DateTime.UtcNow
                    };

                    serializer.Serialize(projectInfo, fs);
                }
            }
            else
            {
                try
                {
                    using (FileStream fs = File.OpenRead(projectPath))
                    {
                        projectInfo = serializer.Deserialize <ProjectInfo>(fs);
                    }
                    projectInfo.Name          = projectName;
                    projectInfo.LastWriteTime = File.GetLastWriteTimeUtc(projectPath);

                    string[] files = Directory.GetFiles(projectDir).Where(fn => fn.EndsWith(".rtbundle")).ToArray();
                    result = new AssetBundleInfo[files.Length];

                    for (int i = 0; i < result.Length; ++i)
                    {
                        using (FileStream fs = File.OpenRead(files[i]))
                        {
                            result[i] = serializer.Deserialize <AssetBundleInfo>(fs);
                        }
                    }
                }
                catch (Exception e)
                {
                    projectInfo     = new ProjectInfo();
                    error.ErrorCode = Error.E_Exception;
                    error.ErrorText = e.ToString();
                }
            }

            callback(error, projectInfo, result);
        }
예제 #17
0
        public void CheckFolderExists(string path, StorageEventHandler <string, bool> callback)
        {
            CombineWithBasePath(ref path);

            bool result = Directory.Exists(path);

            if (callback != null)
            {
                callback(new StoragePayload <string, bool>(path, result));
            }
        }
예제 #18
0
        public void MoveFile(string sourcePath, string destinationPath, StorageEventHandler <string, string> callback)
        {
            CombineWithBasePath(ref sourcePath);
            CombineWithBasePath(ref destinationPath);

            File.Move(sourcePath, destinationPath);
            if (callback != null)
            {
                callback(new StoragePayload <string, string>(sourcePath, destinationPath));
            }
        }
예제 #19
0
        public void ImportProject(string projectPath, string sourcePath, StorageEventHandler callback)
        {
            QueueUserWorkItem(() =>
            {
                try
                {
                    string projectFullPath = FullPath(projectPath);
                    if (Directory.Exists(projectFullPath))
                    {
                        callback(new Error(Error.E_AlreadyExist)
                        {
                            ErrorText = string.Format("Project {0} already exist", projectPath)
                        });
                    }
                    else
                    {
                        FastZip fastZip = new FastZip();
                        fastZip.ExtractZip(sourcePath, projectFullPath, null);

                        ProjectInfo projectInfo;
                        using (FileStream fs = File.OpenRead(projectFullPath + "/Project.rtmeta"))
                        {
                            projectInfo = Serializer.Deserialize <ProjectInfo>(fs);
                        }

                        projectInfo.Name          = Path.GetFileNameWithoutExtension(projectPath);
                        projectInfo.LastWriteTime = File.GetLastWriteTimeUtc(projectFullPath + "/Project.rtmeta");

                        using (FileStream fs = File.OpenWrite(projectFullPath + "/Project.rtmeta"))
                        {
                            Serializer.Serialize(fs, projectInfo);
                        }

                        Callback(() =>
                        {
                            callback(new Error(Error.OK));
                        });
                    }
                }
                catch (Exception e)
                {
                    Callback(() =>
                    {
                        callback(new Error(Error.E_Exception)
                        {
                            ErrorText = e.ToString()
                        });
                    });
                }
            });
        }
예제 #20
0
        public void SaveFiles(string[] path, byte[][] data, StorageEventHandler <string[]> callback)
        {
            CombineWithBasePath(ref path);

            for (int i = 0; i < path.Length; ++i)
            {
                File.WriteAllBytes(path[i], data[i]);
            }

            if (callback != null)
            {
                callback(new StoragePayload <string[]>(path));
            }
        }
예제 #21
0
        public void LoadFile(string path, StorageEventHandler <string, byte[]> callback)
        {
            CombineWithBasePath(ref path);
            byte[] data = null;
            if (File.Exists(path))
            {
                data = File.ReadAllBytes(path);
            }

            if (callback != null)
            {
                callback(new StoragePayload <string, byte[]>(path, data));
            }
        }
예제 #22
0
        public void Create(string projectPath, string[] paths, string[] names, StorageEventHandler callback)
        {
            string fullPath = FullPath(projectPath);

            for (int i = 0; i < paths.Length; ++i)
            {
                string path = fullPath + paths[i] + "/" + names[i];
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            callback(new Error(Error.OK));
        }
예제 #23
0
        public void DeleteFolders(string[] path, StorageEventHandler <string[]> callback)
        {
            CombineWithBasePath(ref path);

            for (int i = 0; i < path.Length; ++i)
            {
                Directory.Delete(path[i], true);
            }

            if (callback != null)
            {
                callback(new StoragePayload <string[]>(path));
            }
        }
예제 #24
0
        public void CreateFolder(string path, StorageEventHandler <string> callback)
        {
            CombineWithBasePath(ref path);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (callback != null)
            {
                callback(new StoragePayload <string>(path));
            }
        }
예제 #25
0
        public void GetProjectTree(string projectPath, StorageEventHandler <ProjectItem> callback)
        {
            projectPath = AssetsFolderPath(projectPath);

            ProjectItem assets = new ProjectItem();

            assets.ItemID   = 0;
            assets.Children = new List <ProjectItem>();
            assets.Name     = "Assets";

            GetProjectTree(projectPath, assets);

            callback(new Error(), assets);
        }
예제 #26
0
        public void MoveFolders(string[] sourcePath, string[] destinationPath, StorageEventHandler <string[], string[]> callback)
        {
            CombineWithBasePath(ref sourcePath);
            CombineWithBasePath(ref destinationPath);

            for (int i = 0; i < sourcePath.Length; ++i)
            {
                Directory.Move(sourcePath[i], destinationPath[i]);
            }

            if (callback != null)
            {
                callback(new StoragePayload <string[], string[]>(sourcePath, destinationPath));
            }
        }
예제 #27
0
 public void DeleteProject(string projectPath, StorageEventHandler callback)
 {
     QueueUserWorkItem(() =>
     {
         string projectDir = FullPath(projectPath);
         if (Directory.Exists(projectDir))
         {
             Directory.Delete(projectDir, true);
         }
         Callback(() =>
         {
             callback(new Error(Error.OK));
         });
     });
 }
예제 #28
0
        public void CopyFolder(string sourcePath, string destinationPath, StorageEventHandler <string, string> callback)
        {
            CombineWithBasePath(ref sourcePath);
            CombineWithBasePath(ref destinationPath);

            DirectoryInfo source      = new DirectoryInfo(sourcePath);
            DirectoryInfo destination = new DirectoryInfo(destinationPath);

            CopyAll(source, destination);

            if (callback != null)
            {
                callback(new StoragePayload <string, string>(sourcePath, destinationPath));
            }
        }
예제 #29
0
        private TrinityErrorCode RaiseStorageEvent(StorageEventHandler handler, string handlerName)
        {
            var ret       = TrinityErrorCode.E_SUCCESS;
            var listeners = handler.GetInvocationList();

            foreach (var listener in listeners)
            {
                try { listener.DynamicInvoke(); }
                catch (Exception ex)
                {
                    Log.WriteLine(LogLevel.Error, $"An error oucurred in {handlerName}: {{0}}", ex.ToString());
                    ret = TrinityErrorCode.E_FAILURE;
                }
            }
            return(ret);
        }
예제 #30
0
        public void GetValue(string projectPath, string key, Type type, StorageEventHandler <PersistentObject> callback)
        {
            string fullPath = FullPath(projectPath);
            string path     = fullPath + "/" + KeyValueStorage;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            path = path + "/" + key;
            if (File.Exists(path))
            {
                object result = null;
                if (type == typeof(PersistentRuntimeTextAsset))
                {
                    PersistentRuntimeTextAsset textAsset = new PersistentRuntimeTextAsset();
                    textAsset.name = Path.GetFileName(path);
                    textAsset.Text = File.ReadAllText(path);
                    textAsset.Ext  = Path.GetExtension(path);
                    result         = textAsset;
                }
                else if (type == typeof(PersistentRuntimeBinaryAsset))
                {
                    PersistentRuntimeBinaryAsset binaryAsset = new PersistentRuntimeBinaryAsset();
                    binaryAsset.name = Path.GetFileName(path);
                    binaryAsset.Data = File.ReadAllBytes(path);
                    binaryAsset.Ext  = Path.GetExtension(path);
                    result           = binaryAsset;
                }
                else
                {
                    ISerializer serializer = IOC.Resolve <ISerializer>();
                    using (FileStream fs = File.OpenRead(path))
                    {
                        result = serializer.Deserialize(fs, type);
                    }
                }

                callback(new Error(Error.OK), (PersistentObject)result);
            }
            else
            {
                callback(new Error(Error.E_NotFound), null);
                return;
            }
        }