// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // initOpenWorkspace // // Description: // Procedure to validate and open a workspace during startup. // The workspace directory must exist and have appropriate permissions // before we attempt to use it. // This procedure is only intended for use during initial startup // and deliberately does not contain any output or superfluous logic. // global proc int initOpenWorkspace(string $workspaceRoot, int $requireWorkspaceExists) { // Check root is a directory and exists if ( !(`filetest -d $workspaceRoot`)) return false; // Check root directory is readable if ( !(`filetest -r $workspaceRoot`)) return false; // Directory permissions on linux & mac need execute as well if (( `about -linux` || `about -mac`) && (!`filetest -x $workspaceRoot`)) return false; // (Optional) Make sure there is an existing workspace.mel if ($requireWorkspaceExists) { string $wsFile = $workspaceRoot + "/" + "workspace.mel"; if (!`filetest -e $wsFile` ) return false; } // Open the workspace if (catch(`workspace -o $workspaceRoot`)) { return false; } return true; }