private static bool PickBuildLocation(BuildTargetGroup targetGroup, BuildTarget target, BuildOptions options, out bool updateExistingBuild)
{
updateExistingBuild = false;
var previousPath = EditorUserBuildSettings.GetBuildLocation(target);
string defaultFolder;
string defaultName;
if (previousPath == String.Empty)
{
defaultFolder = FileUtil.DeleteLastPathNameComponent(Application.dataPath);
defaultName = "";
}
else
{
defaultFolder = FileUtil.DeleteLastPathNameComponent(previousPath);
defaultName = FileUtil.GetLastPathNameComponent(previousPath);
}
string extension = PostprocessBuildPlayer.GetExtensionForBuildTarget(targetGroup, target, options);
// Invalidate default name, if extension mismatches the default file (for ex., when switching between folder type export to file type export, see Android)
if (extension != Path.GetExtension(defaultName).Replace(".", ""))
{
defaultName = string.Empty;
}
// Hack: For Windows Standalone, we want the BuildPanel to choose a folder,
// but we don't want BuildPlayer to take a folder path because historically it took an .exe path
// and we would be breaking tons of projects!
bool isWindowsStandalone = target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64;
string realExtension = extension;
if (isWindowsStandalone)
{
extension = string.Empty;
// Remove the filename.exe part from the path
if (!string.IsNullOrEmpty(defaultName))
{
defaultName = Path.GetDirectoryName(defaultName);
}
}
string title = "Build " + BuildPlatforms.instance.GetBuildTargetDisplayName(targetGroup, target);
string path = EditorUtility.SaveBuildPanel(target, title, defaultFolder, defaultName, extension, out updateExistingBuild);
if (path == string.Empty)
{
return(false);
}
if (isWindowsStandalone)
{
extension = realExtension;
path = Path.Combine(path, Paths.MakeValidFileName(PlayerSettings.productName) + '.' + extension);
}
if (!IsBuildPathValid(path))
{
return(false);
}
// Enforce extension if needed
if (extension != string.Empty && FileUtil.GetPathExtension(path).ToLower() != extension)
{
path += '.' + extension;
}
// A path may not be empty initially, but it could contain, e.g., a drive letter (as in Windows),
// so even appending an extension will work fine, but in reality the name will be, for example,
// G:/
//Debug.Log(path);
string currentlyChosenName = FileUtil.GetLastPathNameComponent(path);
if (currentlyChosenName == string.Empty)
{
return(false); // No nameless projects, please
}
// We don't want to re-create a directory that already exists, this may
// result in access-denials that will make users unhappy.
string check_dir = extension != string.Empty ? FileUtil.DeleteLastPathNameComponent(path) : path;
if (!Directory.Exists(check_dir))
{
Directory.CreateDirectory(check_dir);
}
// On OSX we've got replace/update dialog, for other platforms warn about deleting
// files in target folder.
if ((target == BuildTarget.iOS) && (Application.platform != RuntimePlatform.OSXEditor))
{
if (!FolderIsEmpty(path) && !UserWantsToDeleteFiles(path))
{
return(false);
}
}
EditorUserBuildSettings.SetBuildLocation(target, path);
return(true);
}