Exemplo n.º 1
0
 /// <summary>
 /// Save the <paramref name="course"/> to the file system.
 /// </summary>
 internal static void Save(ICourse course)
 {
     try
     {
         string path       = CourseAssetUtils.GetCourseAssetPath(course.Data.Name);
         byte[] courseData = EditorConfigurator.Instance.Serializer.CourseToByteArray(course);
         WriteCourse(path, courseData);
     }
     catch (Exception ex)
     {
         Debug.LogError(ex);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the course with the given <paramref name="courseName"/> from the file system and converts it into the <seealso cref="ICourse"/> instance.
        /// </summary>
        internal static ICourse Load(string courseName)
        {
            if (CourseAssetUtils.DoesCourseAssetExist(courseName))
            {
                string courseAssetPath = CourseAssetUtils.GetCourseAssetPath(courseName);
                byte[] courseBytes     = File.ReadAllBytes(courseAssetPath);

                try
                {
                    return(EditorConfigurator.Instance.Serializer.CourseFromByteArray(courseBytes));
                }
                catch (Exception ex)
                {
                    Debug.LogError($"Failed to load the course '{courseName}' from '{courseAssetPath}' because of: \n{ex.Message}");
                    Debug.LogError(ex);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renames the <paramref name="course"/> to the <paramref name="newName"/> and moves it to the appropriate directory. Check if you can rename before with the <seealso cref="CanRename"/> method.
        /// </summary>
        internal static void RenameCourse(ICourse course, string newName)
        {
            if (CourseAssetUtils.CanRename(course, newName, out string errorMessage) == false)
            {
                Debug.LogError($"Course {course.Data.Name} was not renamed because:\n\n{errorMessage}");
                return;
            }

            string oldDirectory = CourseAssetUtils.GetCourseAssetDirectory(course.Data.Name);
            string newDirectory = CourseAssetUtils.GetCourseAssetDirectory(newName);

            Directory.Move(oldDirectory, newDirectory);
            File.Move($"{oldDirectory}.meta", $"{newDirectory}.meta");

            string newAsset = CourseAssetUtils.GetCourseAssetPath(newName);
            string oldAsset = $"{CourseAssetUtils.GetCourseAssetDirectory(newName)}/{course.Data.Name}.{EditorConfigurator.Instance.Serializer.FileFormat}";

            File.Move(oldAsset, newAsset);
            File.Move($"{oldAsset}.meta", $"{newAsset}.meta");
            course.Data.Name = newName;

            Save(course);
        }