@@ -143,7 +143,7 @@ define(function (require, exports, module) {
143143 }
144144
145145 async function _validateProjectFolder ( projectPath ) {
146- return new Promise ( async ( resolve , reject ) => {
146+ return new Promise ( ( resolve , reject ) => {
147147 let dir = FileSystem . getDirectoryForPath ( projectPath ) ;
148148 let displayPath = projectPath . replace ( Phoenix . VFS . getMountDir ( ) , "" ) ;
149149 if ( ! dir ) {
@@ -177,45 +177,54 @@ define(function (require, exports, module) {
177177 }
178178
179179 async function _findFreeFolderName ( basePath ) {
180- return new Promise ( async ( resolve , reject ) => {
181- for ( let i = 0 ; i < MAX_DEDUPE_COUNT ; i ++ ) {
182- let newPath = `${ basePath } -${ i } ` ;
183- let exists = await window . Phoenix . VFS . existsAsync ( newPath ) ;
184- if ( ! exists ) {
185- await window . Phoenix . VFS . ensureExistsDirAsync ( newPath ) ;
186- resolve ( newPath ) ;
187- return ;
180+ return new Promise ( async ( resolve , reject ) => { // eslint-disable-line
181+ try {
182+ for ( let i = 0 ; i < MAX_DEDUPE_COUNT ; i ++ ) {
183+ let newPath = `${ basePath } -${ i } ` ;
184+ let exists = await window . Phoenix . VFS . existsAsync ( newPath ) ;
185+ if ( ! exists ) {
186+ await window . Phoenix . VFS . ensureExistsDirAsync ( newPath ) ;
187+ resolve ( newPath ) ;
188+ return ;
189+ }
188190 }
191+ reject ( ) ;
192+ } catch ( e ) {
193+ reject ( e ) ;
189194 }
190- reject ( ) ;
191195 } ) ;
192196 }
193197
194198 async function alreadyExists ( suggestedProjectName ) {
195199 let projectPath = `${ ProjectManager . getLocalProjectsPath ( ) } ${ suggestedProjectName } ` ; // try suggested path first
196- return await window . Phoenix . VFS . existsAsync ( projectPath ) ;
200+ return window . Phoenix . VFS . existsAsync ( projectPath ) ;
197201 }
198202
199203 async function _getSuggestedProjectDir ( suggestedProjectName ) {
200- return new Promise ( async ( resolve , reject ) => {
201- let projectPath = `${ ProjectManager . getLocalProjectsPath ( ) } ${ suggestedProjectName } ` ; // try suggested path first
202- let exists = await window . Phoenix . VFS . existsAsync ( projectPath ) ;
203- if ( ! exists ) {
204- resolve ( projectPath ) ;
205- return ;
206- }
207- _showReplaceKeepProjectConfirmDialogue ( suggestedProjectName ) . done ( function ( id ) {
208- if ( id === Dialogs . DIALOG_BTN_OK ) {
204+ return new Promise ( async ( resolve , reject ) => { // eslint-disable-line
205+ try {
206+ // try suggested path first
207+ let projectPath = `${ ProjectManager . getLocalProjectsPath ( ) } ${ suggestedProjectName } ` ;
208+ let exists = await window . Phoenix . VFS . existsAsync ( projectPath ) ;
209+ if ( ! exists ) {
209210 resolve ( projectPath ) ;
210211 return ;
211- } else if ( id === Dialogs . DIALOG_BTN_CANCEL ) {
212- reject ( ) ;
213- return ;
214212 }
215- _findFreeFolderName ( projectPath )
216- . then ( projectPath => resolve ( projectPath ) )
217- . catch ( reject ) ;
218- } ) ;
213+ _showReplaceKeepProjectConfirmDialogue ( suggestedProjectName ) . done ( function ( id ) {
214+ if ( id === Dialogs . DIALOG_BTN_OK ) {
215+ resolve ( projectPath ) ;
216+ return ;
217+ } else if ( id === Dialogs . DIALOG_BTN_CANCEL ) {
218+ reject ( ) ;
219+ return ;
220+ }
221+ _findFreeFolderName ( projectPath )
222+ . then ( projectPath => resolve ( projectPath ) )
223+ . catch ( reject ) ;
224+ } ) ;
225+ } catch ( e ) {
226+ reject ( e ) ;
227+ }
219228 } ) ;
220229 }
221230
@@ -267,55 +276,61 @@ define(function (require, exports, module) {
267276 * @returns {Promise<void> }
268277 */
269278 async function downloadAndOpenProject ( downloadURL , projectPath , suggestedProjectName , flattenFirstLevelInZip ) {
270- return new Promise ( async ( resolve , reject ) => {
271- // if project path is null, create one in default folder
272- if ( ! projectPath ) {
273- projectPath = await _getSuggestedProjectDir ( suggestedProjectName ) ;
274- } else {
275- await _validateProjectFolder ( projectPath ) ;
276- }
277- console . log ( `downloadAndOpenProject ${ suggestedProjectName } from URL: ${ downloadURL } to: ${ projectPath } ` ) ;
278-
279- downloadCancelled = false ;
280- _showCreateProjectDialogue ( Strings . SETTING_UP_PROJECT , Strings . DOWNLOADING ) . done ( function ( id ) {
281- if ( id === Dialogs . DIALOG_BTN_CANCEL ) {
282- downloadCancelled = true ;
279+ return new Promise ( async ( resolve , reject ) => { // eslint-disable-line
280+ try {
281+ // if project path is null, create one in default folder
282+ if ( ! projectPath ) {
283+ projectPath = await _getSuggestedProjectDir ( suggestedProjectName ) ;
284+ } else {
285+ await _validateProjectFolder ( projectPath ) ;
283286 }
284- } ) ;
285- window . JSZipUtils . getBinaryContent ( downloadURL , {
286- callback : async function ( err , data ) {
287- if ( downloadCancelled ) {
288- reject ( ) ;
289- } else if ( err ) {
290- console . error ( "could not load phoenix default project from zip file!" , err ) ;
291- _closeCreateProjectDialogue ( ) ;
292- showErrorDialogue ( Strings . DOWNLOAD_FAILED , Strings . DOWNLOAD_FAILED_MESSAGE ) ;
293- reject ( ) ;
294- } else {
295- _unzipProject ( data , projectPath , flattenFirstLevelInZip )
296- . then ( ( ) => {
297- _closeCreateProjectDialogue ( ) ;
298- ProjectManager . openProject ( projectPath )
299- . then ( resolve )
300- . fail ( reject ) ;
301- console . log ( "Project Setup complete: " , projectPath ) ;
302- } )
303- . catch ( ( ) => {
304- _closeCreateProjectDialogue ( ) ;
305- showErrorDialogue ( Strings . ERROR_LOADING_PROJECT , Strings . UNZIP_FAILED ) ;
306- reject ( ) ;
307- } ) ;
287+ console . log (
288+ `downloadAndOpenProject ${ suggestedProjectName } from URL: ${ downloadURL } to: ${ projectPath } ` ) ;
289+
290+ downloadCancelled = false ;
291+ _showCreateProjectDialogue ( Strings . SETTING_UP_PROJECT , Strings . DOWNLOADING ) . done ( function ( id ) {
292+ if ( id === Dialogs . DIALOG_BTN_CANCEL ) {
293+ downloadCancelled = true ;
308294 }
309- } ,
310- progress : function ( status ) {
311- if ( status . percent > 0 ) {
312- _updateCreateProjectDialogueMessage ( `${ Strings . DOWNLOADING } ${ Math . round ( status . percent ) } %` ) ;
295+ } ) ;
296+ window . JSZipUtils . getBinaryContent ( downloadURL , {
297+ callback : async function ( err , data ) {
298+ if ( downloadCancelled ) {
299+ reject ( ) ;
300+ } else if ( err ) {
301+ console . error ( "could not load phoenix default project from zip file!" , err ) ;
302+ _closeCreateProjectDialogue ( ) ;
303+ showErrorDialogue ( Strings . DOWNLOAD_FAILED , Strings . DOWNLOAD_FAILED_MESSAGE ) ;
304+ reject ( ) ;
305+ } else {
306+ _unzipProject ( data , projectPath , flattenFirstLevelInZip )
307+ . then ( ( ) => {
308+ _closeCreateProjectDialogue ( ) ;
309+ ProjectManager . openProject ( projectPath )
310+ . then ( resolve )
311+ . fail ( reject ) ;
312+ console . log ( "Project Setup complete: " , projectPath ) ;
313+ } )
314+ . catch ( ( ) => {
315+ _closeCreateProjectDialogue ( ) ;
316+ showErrorDialogue ( Strings . ERROR_LOADING_PROJECT , Strings . UNZIP_FAILED ) ;
317+ reject ( ) ;
318+ } ) ;
319+ }
320+ } ,
321+ progress : function ( status ) {
322+ if ( status . percent > 0 ) {
323+ _updateCreateProjectDialogueMessage (
324+ `${ Strings . DOWNLOADING } ${ Math . round ( status . percent ) } %` ) ;
325+ }
326+ } ,
327+ abortCheck : function ( ) {
328+ return downloadCancelled ;
313329 }
314- } ,
315- abortCheck : function ( ) {
316- return downloadCancelled ;
317- }
318- } ) ;
330+ } ) ;
331+ } catch ( e ) {
332+ reject ( e ) ;
333+ }
319334 } ) ;
320335 }
321336
0 commit comments