Example #1
0
		private static string[] ExportAssets(ContentRef<Resource> inputResource, string exportDir, bool simulate)
		{
			// Early-out, if the input Resource isn't available
			if (!inputResource.IsAvailable) return new string[0];

			// If there is no export directory set, derive it from the Resource path in the Data folder
			if (exportDir == null)
			{
				string resFullNameInData = PathHelper.MakeFilePathRelative(inputResource.FullName, DualityApp.DataDirectory);
				string resDirInData = Path.GetDirectoryName(resFullNameInData);
				exportDir = Path.Combine(
					EditorHelper.SourceMediaDirectory,
					resDirInData);
			}

			bool userAbort = false;
			bool success = false;

			// Set up an export operation and process it
			AssetExportOperation exportOperation = new AssetExportOperation(inputResource.Res, exportDir);
			exportOperation.ImporterConflictHandler = data =>
			{
				IAssetImporter userSelection = ResolveImporterConflict(data);
				if (userSelection == null) userAbort = true;
				return userSelection;
			};
			success = simulate ?
				exportOperation.SimulatePerform() :
				exportOperation.Perform();

			// If the operation was a failure, display an error message in the editor UI.
			if (!simulate && !success && !userAbort)
			{
				MessageBox.Show(
					string.Format(Properties.GeneralRes.Msg_CantExport_Text, inputResource.Path), 
					Properties.GeneralRes.Msg_CantExport_Caption, 
					MessageBoxButtons.OK, 
					MessageBoxIcon.Error);
			}

			return exportOperation.OutputPaths.ToArray();
		}