|
|
@@ -53,28 +53,30 @@ bool AssetImporter::SaveSettingsInternal(JSONValue& jsonRoot)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool AssetImporter::Rename(const String& newName)
|
|
|
+bool AssetImporter::Move(const String& newPath)
|
|
|
{
|
|
|
- String pathName, fileName, ext;
|
|
|
-
|
|
|
- SplitPath(asset_->path_, pathName, fileName, ext);
|
|
|
-
|
|
|
- String newPath = pathName + newName + ext;
|
|
|
-
|
|
|
FileSystem* fs = GetSubsystem<FileSystem>();
|
|
|
|
|
|
- if (fs->FileExists(newPath) || fs->DirExists(newPath))
|
|
|
+ if (newPath == asset_->path_)
|
|
|
return false;
|
|
|
|
|
|
- // rename asset first, ahead of the filesystem watcher
|
|
|
String oldPath = asset_->path_;
|
|
|
+ String oldName = asset_->name_;
|
|
|
+
|
|
|
+ String pathName, newName, ext;
|
|
|
|
|
|
+ SplitPath(newPath, pathName, newName, ext);
|
|
|
+
|
|
|
+ // rename asset first, ahead of the filesystem watcher, so the assetdatabase doesn't see a new asset
|
|
|
asset_->name_ = newName;
|
|
|
asset_->path_ = newPath;
|
|
|
|
|
|
// first rename the .asset file
|
|
|
if (!fs->Rename(oldPath + ".asset", newPath + ".asset"))
|
|
|
{
|
|
|
+ asset_->name_ = oldName;
|
|
|
+ asset_->path_ = oldPath;
|
|
|
+
|
|
|
LOGERRORF("Unable to rename asset: %s to %s", GetNativePath(oldPath + ".asset").CString(), GetNativePath(newPath + ".asset").CString());
|
|
|
return false;
|
|
|
}
|
|
|
@@ -82,6 +84,9 @@ bool AssetImporter::Rename(const String& newName)
|
|
|
// now rename the asset file itself
|
|
|
if (!fs->Rename(oldPath, newPath))
|
|
|
{
|
|
|
+ asset_->name_ = oldName;
|
|
|
+ asset_->path_ = oldPath;
|
|
|
+
|
|
|
// restore .asset
|
|
|
fs->Rename(newPath + ".asset", oldPath + ".asset");
|
|
|
|
|
|
@@ -90,6 +95,22 @@ bool AssetImporter::Rename(const String& newName)
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool AssetImporter::Rename(const String& newName)
|
|
|
+{
|
|
|
+ String pathName, fileName, ext;
|
|
|
+
|
|
|
+ SplitPath(asset_->path_, pathName, fileName, ext);
|
|
|
+
|
|
|
+ String newPath = pathName + newName + ext;
|
|
|
+
|
|
|
+ FileSystem* fs = GetSubsystem<FileSystem>();
|
|
|
+
|
|
|
+ if (fs->FileExists(newPath) || fs->DirExists(newPath))
|
|
|
+ return false;
|
|
|
+
|
|
|
+ return Move(newPath);
|
|
|
|
|
|
}
|
|
|
|