Parcourir la source

When opening a project without Internal folder, properly create the folder and its default data

BearishSun il y a 9 ans
Parent
commit
bb9c995f07

+ 3 - 0
Source/BansheeEditor/Include/BsEditorApplication.h

@@ -116,6 +116,9 @@ namespace BansheeEngine
 		/**	Saves the provided widget layout at the default layout location. */
 		/**	Saves the provided widget layout at the default layout location. */
 		void saveWidgetLayout(const SPtr<EditorWidgetLayout>& layout);
 		void saveWidgetLayout(const SPtr<EditorWidgetLayout>& layout);
 
 
+		/** Saves the default widget layout in the current project folder. */
+		void saveDefaultWidgetLayout();
+
 		/** Loads the previously saved editor settings from the default location. Overwrites any current settings. */
 		/** Loads the previously saved editor settings from the default location. Overwrites any current settings. */
 		void loadEditorSettings();
 		void loadEditorSettings();
 
 

+ 22 - 8
Source/BansheeEditor/Source/BsEditorApplication.cpp

@@ -280,14 +280,7 @@ namespace BansheeEngine
 		if (!FileSystem::exists(internalResourcesDir))
 		if (!FileSystem::exists(internalResourcesDir))
 			FileSystem::createDir(internalResourcesDir);
 			FileSystem::createDir(internalResourcesDir);
 
 
-		Path defaultLayoutPath = FileSystem::getWorkingDirectoryPath();
-		defaultLayoutPath.append(BuiltinEditorResources::getDefaultWidgetLayoutPath());
-
-		if (FileSystem::exists(defaultLayoutPath))
-		{
-			Path projectLayoutPath = Path::combine(path, WIDGET_LAYOUT_PATH);
-			FileSystem::copy(defaultLayoutPath, projectLayoutPath, false);
-		}
+		saveDefaultWidgetLayout();
 	}
 	}
 
 
 	bool EditorApplication::isValidProjectPath(const Path& path)
 	bool EditorApplication::isValidProjectPath(const Path& path)
@@ -306,6 +299,9 @@ namespace BansheeEngine
 		Path layoutPath = getProjectPath();
 		Path layoutPath = getProjectPath();
 		layoutPath.append(WIDGET_LAYOUT_PATH);
 		layoutPath.append(WIDGET_LAYOUT_PATH);
 
 
+		if (!FileSystem::exists(layoutPath))
+			saveDefaultWidgetLayout();
+
 		if(FileSystem::exists(layoutPath))
 		if(FileSystem::exists(layoutPath))
 		{
 		{
 			FileDecoder fs(layoutPath);
 			FileDecoder fs(layoutPath);
@@ -324,6 +320,24 @@ namespace BansheeEngine
 		fs.encode(layout.get());
 		fs.encode(layout.get());
 	}
 	}
 
 
+	void EditorApplication::saveDefaultWidgetLayout()
+	{
+		Path resourceDir = Path::combine(mProjectPath, ProjectLibrary::RESOURCES_DIR);
+		Path internalResourcesDir = Path::combine(mProjectPath, ProjectLibrary::INTERNAL_RESOURCES_DIR);
+
+		if (!FileSystem::exists(internalResourcesDir))
+			FileSystem::createDir(internalResourcesDir);
+
+		Path defaultLayoutPath = FileSystem::getWorkingDirectoryPath();
+		defaultLayoutPath.append(BuiltinEditorResources::getDefaultWidgetLayoutPath());
+
+		if (FileSystem::exists(defaultLayoutPath))
+		{
+			Path projectLayoutPath = Path::combine(mProjectPath, WIDGET_LAYOUT_PATH);
+			FileSystem::copy(defaultLayoutPath, projectLayoutPath, false);
+		}
+	}
+
 	void EditorApplication::loadEditorSettings()
 	void EditorApplication::loadEditorSettings()
 	{
 	{
 		Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();
 		Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();

+ 15 - 12
Source/BansheeEditor/Source/BsProjectLibrary.cpp

@@ -1455,23 +1455,26 @@ namespace BansheeEngine
 		Path internalResourcesFolder = mProjectFolder;
 		Path internalResourcesFolder = mProjectFolder;
 		internalResourcesFolder.append(INTERNAL_RESOURCES_DIR);
 		internalResourcesFolder.append(INTERNAL_RESOURCES_DIR);
 
 
-		Vector<Path> toDelete;
-		auto processFile = [&](const Path& file)
+		if (FileSystem::exists(internalResourcesFolder))
 		{
 		{
-			String uuid = file.getFilename(false);
-			if (mUUIDToPath.find(uuid) == mUUIDToPath.end())
+			Vector<Path> toDelete;
+			auto processFile = [&](const Path& file)
 			{
 			{
-				mResourceManifest->unregisterResource(uuid);
-				toDelete.push_back(file);
-			}
+				String uuid = file.getFilename(false);
+				if (mUUIDToPath.find(uuid) == mUUIDToPath.end())
+				{
+					mResourceManifest->unregisterResource(uuid);
+					toDelete.push_back(file);
+				}
 
 
-			return true;
-		};
+				return true;
+			};
 
 
-		FileSystem::iterate(internalResourcesFolder, processFile);
+			FileSystem::iterate(internalResourcesFolder, processFile);
 
 
-		for (auto& entry : toDelete)
-			FileSystem::remove(entry);
+			for (auto& entry : toDelete)
+				FileSystem::remove(entry);
+		}
 
 
 		mIsLoaded = true;
 		mIsLoaded = true;
 	}
 	}