示例#1
0
        public static StudioProject OpenProject(String path)
        {
            // Deserialize project from file
            StudioProject project = null;

            using (var stream = new StreamEx(path))
            {
                project = JsonUtils.Deserialize <StudioProject>(stream);
            }
            project.ProjectDirectory = Path.GetDirectoryName(path);

            // Sync raw lists to models
            project.assets = new Dictionary <string, AssetBase>();
            foreach (var p in project.RawAssets)
            {
                var factory = AssetLoaders[p.AssetLoader];
                project.assets.Add(p.Name, factory.Create(project, p.Name, p.Filename));
            }

            // Set up cache manager
            project.CacheManager = new CacheManager(project);

            // TODO Load up other stuff


            return(project);
        }
示例#2
0
        public static StudioProject CreateProject(String path, String name)
        {
            // Check argument
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            // Make sure root directory is there
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // Set up the project
            var project = new StudioProject {
                Name = name, Fps = 10
            };

            project.ProjectDirectory = path;

            // Set up directories
            if (!Directory.Exists(project.GetAssetDirectory()))
            {
                Directory.CreateDirectory(project.GetAssetDirectory());
            }

            project.SaveProject();

            // Create cache
            project.CacheManager = new CacheManager(project);

            return(project);
        }
示例#3
0
        /// <summary>
        ///     Constructor.
        ///     Creates a cache manager for the specified StudioProject.
        /// </summary>
        /// <param name="project"></param>
        public CacheManager(StudioProject project) : this()
        {
            logger.Info("Creating new StudioCacheManager instance...");

            Project = project;

            // Construct paths
            string indexPath = Path.Combine(project.ProjectDirectory, IndexFile);
            string dataPath  = Path.Combine(project.ProjectDirectory, DataFile);

            Initialize(indexPath, dataPath);
        }
示例#4
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="project">The project that this asset is associated with.</param>
        /// <param name="name">Name of the asset.</param>
        /// <param name="filename">Name of the asset file in the asset folder.</param>
        protected AssetBase(StudioProject project, String name, String filename)
        {
            try
            {
                Project = project;
                Name = name;
                Filename = filename;

                string strID = Path.GetFileNameWithoutExtension(filename);
                ID = Guid.Parse(strID);

                if (!File.Exists(Path.Combine(Project.GetAssetDirectory(), Filename)))
                    throw new FileNotFoundException("Asset file not found!");
            }
            catch (Exception x) {
                Error = x;
            }
        }
示例#5
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="project">The project that this asset is associated with.</param>
        /// <param name="name">Name of the asset.</param>
        /// <param name="filename">Name of the asset file in the asset folder.</param>
        protected AssetBase(StudioProject project, String name, String filename)
        {
            try
            {
                Project  = project;
                Name     = name;
                Filename = filename;

                string strID = Path.GetFileNameWithoutExtension(filename);
                ID = Guid.Parse(strID);

                if (!File.Exists(Path.Combine(Project.GetAssetDirectory(), Filename)))
                {
                    throw new FileNotFoundException("Asset file not found!");
                }
            }
            catch (Exception x) {
                Error = x;
            }
        }
示例#6
0
        /// <summary>
        /// Pushes a project into the recent projects list.
        /// Pinned projects will not be removed.
        /// </summary>
        /// <param name="project"></param>
        public void PushRecentProject(StudioProject project)
        {
            var existing =
                RecentProjects.FindIndex(i => i.ID.Equals(project.Guid));

            if (existing == -1)
            {
                logger.Info("Adding {0} to the recent project list.", project.Name);
                var info = new RecentProjectInfo
                {
                    ID = project.Guid,
                    Name = project.Name,
                    Path = Path.Combine(project.ProjectDirectory, StudioProject.PROJECT_FILE),
                    IsPinned = false
                };

                // If the list if at capacity
                if (RecentProjects.Count >= RecentProjectsListCapacity)
                {
                    // Remove the last unpinned entry
                    var unpinned = RecentProjects.FindLastIndex(i => !i.IsPinned);
                    if (unpinned != -1)
                    {
                        RecentProjects.RemoveAt(unpinned);
                        RecentProjects.Insert(0, info);
                        FirePropertyChanged("RecentProjects");
                        logger.Trace("Recent projects list at capacity, removed the last unpinned.");
                    }
                    else logger.Trace("Recent projects list at capacity, no unpinned entries to remove.");
                }
                else
                {
                    RecentProjects.Insert(0, info);
                    FirePropertyChanged("RecentProjects");
                }
            }
            else
            {
                logger.Info("Moving {0} to the top of the RecentProjects list.", project.Name);
                var info = RecentProjects[existing];
                RecentProjects.RemoveAt(existing);
                RecentProjects.Insert(0, info);
            }
        }
示例#7
0
        public static StudioProject CreateProject(String path, String name)
        {
            // Check argument
            if (path == null) throw new ArgumentNullException("path");

            // Make sure root directory is there
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            // Set up the project
            var project = new StudioProject { Name = name, Fps = 10 };
            project.ProjectDirectory = path;

            // Set up directories
            if (!Directory.Exists(project.GetAssetDirectory()))
                Directory.CreateDirectory(project.GetAssetDirectory());

            project.SaveProject();

            // Create cache
            project.CacheManager = new CacheManager(project);

            return project;
        }