@@ -182,7 +182,7 @@ private static string MAYA_COMMANDS { get {
182
182
} }
183
183
private static Char [ ] FIELD_SEPARATORS = new Char [ ] { ':' } ;
184
184
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" ;
186
186
187
187
#if UNITY_EDITOR_OSX
188
188
private const string MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/modules" ;
@@ -508,18 +508,7 @@ class IntegrationsUI
508
508
509
509
public static void InstallMayaIntegration ( )
510
510
{
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 ( ) ;
523
512
return ;
524
513
525
514
var mayaVersion = new Integrations . MayaVersion ( ) ;
@@ -540,19 +529,74 @@ public static void InstallMayaIntegration ()
540
529
UnityEditor . EditorUtility . DisplayDialog ( title , message , "Ok" ) ;
541
530
}
542
531
543
- private static bool hasWriteAccessToFolder ( string folderPath )
532
+ private static void DecompressIntegrationZipFile ( )
544
533
{
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
+ }
551
552
}
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 ) ) {
554
597
return false ;
555
598
}
599
+ return true ;
556
600
}
557
601
558
602
public static void DecompressZip ( string zipPath , string destPath ) {
0 commit comments