Skip to content

Commit 1461c43

Browse files
committed
make sure user selects valid location to decompress
and prompt the user on what to do if the location already has the unzipped contents of the file
1 parent 699d7ac commit 1461c43

File tree

1 file changed

+66
-22
lines changed

1 file changed

+66
-22
lines changed

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static string MAYA_COMMANDS { get {
182182
}}
183183
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
184184

185-
private const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
185+
public const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya/" + MODULE_FILENAME + ".txt";
186186

187187
#if UNITY_EDITOR_OSX
188188
private const string MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/modules";
@@ -508,18 +508,7 @@ class IntegrationsUI
508508

509509
public static void InstallMayaIntegration ()
510510
{
511-
// prompt user to enter location to unzip file
512-
var unzipFolder = EditorUtility.OpenFolderPanel("Select Location to Save Maya Integration",LastIntegrationSavePath,"");
513-
Debug.Log (unzipFolder);
514-
515-
// check that this is a valid location to unzip the file
516-
517-
518-
// if file already unzipped in this location, then prompt user
519-
// if they would like to continue unzipping or use what is there
520-
521-
// unzip Integration folder
522-
DecompressZip(Application.dataPath + "/" + IntegrationZipPath, Application.dataPath + "/TestIntegrations");
511+
DecompressIntegrationZipFile ();
523512
return;
524513

525514
var mayaVersion = new Integrations.MayaVersion();
@@ -540,19 +529,74 @@ public static void InstallMayaIntegration ()
540529
UnityEditor.EditorUtility.DisplayDialog (title, message, "Ok");
541530
}
542531

543-
private static bool hasWriteAccessToFolder(string folderPath)
532+
private static void DecompressIntegrationZipFile()
544533
{
545-
try
546-
{
547-
// Attempt to get a list of security permissions from the folder.
548-
// This will raise an exception if the path is read only or do not have access to view the permissions.
549-
System.Security.AccessControl.DirectorySecurity ds = System.IO.Directory.GetAccessControl(folderPath);
550-
return true;
534+
// prompt user to enter location to unzip file
535+
var unzipFolder = EditorUtility.OpenFolderPanel("Select Location to Save Maya Integration",LastIntegrationSavePath,"");
536+
Debug.Log (unzipFolder);
537+
538+
// check that this is a valid location to unzip the file
539+
if (!DirectoryHasWritePermission (unzipFolder)) {
540+
// display dialog to try again or cancel
541+
var result = UnityEditor.EditorUtility.DisplayDialog ("No Write Permission",
542+
string.Format("Directory \"{0}\" does not have write access", unzipFolder),
543+
"Select another Directory",
544+
"Cancel"
545+
);
546+
547+
if (result) {
548+
InstallMayaIntegration ();
549+
} else {
550+
return;
551+
}
551552
}
552-
catch (UnauthorizedAccessException)
553-
{
553+
554+
LastIntegrationSavePath = unzipFolder;
555+
556+
// if file already unzipped in this location, then prompt user
557+
// if they would like to continue unzipping or use what is there
558+
if (FolderAlreadyUnzippedAtPath (unzipFolder)) {
559+
var result = UnityEditor.EditorUtility.DisplayDialogComplex ("Integrations Exist at Path",
560+
string.Format ("Directory \"{0}\" already contains the decompressed integration", unzipFolder),
561+
"Overwrite",
562+
"Use Existing",
563+
"Cancel"
564+
);
565+
566+
if (result == 0) {
567+
DecompressZip (Application.dataPath + "/" + IntegrationZipPath, unzipFolder);
568+
} else if (result == 2) {
569+
return;
570+
}
571+
} else {
572+
// unzip Integration folder
573+
DecompressZip (Application.dataPath + "/" + IntegrationZipPath, unzipFolder);
574+
}
575+
}
576+
577+
/// <summary>
578+
/// Determines if folder is already unzipped at the specified path
579+
/// by checking if unityoneclick.txt exists at expected location.
580+
/// </summary>
581+
/// <returns><c>true</c> if folder is already unzipped at the specified path; otherwise, <c>false</c>.</returns>
582+
/// <param name="path">Path.</param>
583+
public static bool FolderAlreadyUnzippedAtPath(string path)
584+
{
585+
return System.IO.File.Exists (System.IO.Path.Combine (path, Integrations.MODULE_TEMPLATE_PATH));
586+
}
587+
588+
/// <summary>
589+
/// Check if the directory has write permission.
590+
/// TODO: find a way to do this that works in Unity
591+
/// </summary>
592+
/// <returns><c>true</c>, if has write permission was directoryed, <c>false</c> otherwise.</returns>
593+
/// <param name="path">Path.</param>
594+
public static bool DirectoryHasWritePermission(string path)
595+
{
596+
if (!System.IO.Directory.Exists (path)) {
554597
return false;
555598
}
599+
return true;
556600
}
557601

558602
public static void DecompressZip(string zipPath, string destPath){

0 commit comments

Comments
 (0)