@@ -268,19 +268,22 @@ function downloadCode() {
268268} ;
269269
270270function uploadCode ( ) {
271- $ ( '#upload-dialog' ) . modal ( 'show' ) ;
271+ if ( checkLeave ( ) ) {
272+ utils . showMessage ( 'Unsaved Project' , 'You must save your project before you can upload a blocks file to it.' ) ;
273+ } else {
274+ $ ( '#upload-dialog' ) . modal ( 'show' ) ;
275+ }
272276} ;
273277
274278function uploadHandler ( files ) {
275-
276279 var UploadReader = new FileReader ( ) ;
277280 UploadReader . onload = function ( ) {
278281 //var parsed = new DOMParser().parseFromString(this.result, "text/xml");
279282 //var xmlString = (new XMLSerializer()).serializeToString(parsed);
280283 var xmlString = this . result ;
281284 var xmlValid = false ;
282285 var uploadBoardType = '' ;
283-
286+
284287 //validate file, screen for potentially malicious code.
285288 if ( files [ 0 ] . type === 'image/svg+xml'
286289 && xmlString . indexOf ( "<svg blocklyprop=\"blocklypropproject\"" ) === 0
@@ -292,9 +295,9 @@ function uploadHandler(files) {
292295 uploadedXML = xmlString . substring ( xmlString . indexOf ( "<block" ) , ( xmlString . length - 29 ) ) ;
293296 var computedChecksum = hashCode ( uploadedXML ) . toString ( ) ;
294297 computedChecksum = '000000000000' . substring ( computedChecksum . length , 12 ) + computedChecksum ;
295-
298+
296299 if ( computedChecksum === uploadedChecksum ) xmlValid = true ;
297-
300+
298301 if ( xmlValid ) {
299302 var boardIndex = xmlString . indexOf ( 'transform="translate(-225,-23)">Device: ' ) ;
300303 uploadBoardType = xmlString . substring ( ( boardIndex + 40 ) , xmlString . indexOf ( '</text>' , ( boardIndex + 41 ) ) ) ;
@@ -305,8 +308,8 @@ function uploadHandler(files) {
305308 }
306309 }
307310 } ;
308-
309-
311+
312+
310313 if ( xmlValid === true ) {
311314 document . getElementById ( "selectfile-verify-valid" ) . style . display = "block" ;
312315 document . getElementById ( "selectfile-replace" ) . disabled = false ;
@@ -319,11 +322,11 @@ function uploadHandler(files) {
319322 uploadedXML = '' ;
320323 }
321324 } ;
322-
325+
323326 UploadReader . readAsText ( files [ 0 ] ) ;
324-
327+
325328 if ( uploadedXML !== '' ) {
326-
329+
327330 uploadedXML = '<xml xmlns="http://www.w3.org/1999/xhtml">' + uploadedXML + '</xml>' ;
328331 } ;
329332} ;
0 commit comments