| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* globals zip */ |
| 8 |
| 9 'use strict'; |
| 10 |
| 7 var PAK_FILE = 'id1/pak0.pak'; | 11 var PAK_FILE = 'id1/pak0.pak'; |
| 8 | 12 |
| 9 function updateStatus(message) { | 13 function updateStatus(message) { |
| 10 document.getElementById('status').innerHTML += message + '<br />'; | 14 document.getElementById('status').innerHTML += message + '<br />'; |
| 11 } | 15 } |
| 12 | 16 |
| 13 /* | 17 /* |
| 14 * Creates and add to the DOM the NaCl embed tag which | 18 * Creates and add to the DOM the NaCl embed tag which |
| 15 * in effect launches Quake. | 19 * in effect launches Quake. |
| 16 */ | 20 */ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 updateStatus('Extracting file: ' + file.name); | 63 updateStatus('Extracting file: ' + file.name); |
| 60 zip.createReader(new zip.BlobReader(file), | 64 zip.createReader(new zip.BlobReader(file), |
| 61 function(zipReader) { | 65 function(zipReader) { |
| 62 zipReader.getEntries(function(entries) { | 66 zipReader.getEntries(function(entries) { |
| 63 extractNextEntry(entries, 0, filesystem, oncomplete); | 67 extractNextEntry(entries, 0, filesystem, oncomplete); |
| 64 }); | 68 }); |
| 65 }, | 69 }, |
| 66 function() { | 70 function() { |
| 67 updateStatus('Error reading zip file'); | 71 updateStatus('Error reading zip file'); |
| 68 } | 72 } |
| 69 ) | 73 ); |
| 70 } | 74 } |
| 71 | 75 |
| 72 function uploadDidChange(event) { | 76 function uploadDidChange(event) { |
| 73 function oncomplete() { | 77 function oncomplete() { |
| 74 // Once we have extracted all the files then | 78 // Once we have extracted all the files then |
| 75 // launch the game. | 79 // launch the game. |
| 76 updateStatus("Extracted all file. Launching Quake."); | 80 updateStatus("Extracted all file. Launching Quake."); |
| 77 runQuake('/tmp'); | 81 runQuake('/tmp'); |
| 78 } | 82 } |
| 79 | 83 |
| 80 window.webkitRequestFileSystem(window.TEMPORARY, 50 * 1024 * 1024, | 84 window.webkitRequestFileSystem(window.TEMPORARY, 50 * 1024 * 1024, |
| 81 function(fs) { | 85 function(fs) { |
| 82 var file = event.target.files[0]; | 86 var file = event.target.files[0]; |
| 83 extractZipFile(file, fs, oncomplete); | 87 extractZipFile(file, fs, oncomplete); |
| 84 }, | 88 }, |
| 85 function() { | 89 function() { |
| 86 updateStatus('Error accessing html5 filesystem.'); | 90 updateStatus('Error accessing html5 filesystem.'); |
| 87 } | 91 } |
| 88 ); | 92 ); |
| 89 } | 93 } |
| 90 | 94 |
| 91 function loadFromLocalStorage() { | 95 function loadFromLocalStorage() { |
| 92 function loadFailure() { | 96 function loadFailure() { |
| 93 updateStatus('Quake data not found in local html5 filesystem.'); | 97 updateStatus('Quake data not found in local html5 filesystem.'); |
| 94 updateStatus('Please locate a quake level set (for example the ' | 98 updateStatus('Please locate a quake level set (for example the ' + |
| 95 + '<a href="http://www.libsdl.org/projects/quake/data/quakesw-1.0.6.zip">' | 99 '<a href="http://www.libsdl.org/projects/quake/data/quakesw-1.0.6.zip">' + |
| 96 + 'shareware levels</a>) and either extract them alongside the nmf file,' | 100 'shareware levels</a>) and either extract them alongside the nmf file,' + |
| 97 + ' or use the upload button below to unzip them in the local html5' | 101 ' or use the upload button below to unzip them in the local html5' + |
| 98 + ' filesystem.'); | 102 ' filesystem.'); |
| 99 // Create an html5 file input elemnt in so the user can upload the game | 103 // Create an html5 file input elemnt in so the user can upload the game |
| 100 // data as a zip file. | 104 // data as a zip file. |
| 101 document.getElementById('quake').innerHTML = | 105 document.getElementById('quake').innerHTML = |
| 102 '<input type="file" accept="application/zip" id="infile">'; | 106 '<input type="file" accept="application/zip" id="infile">'; |
| 103 document.getElementById('infile').addEventListener('change', | 107 document.getElementById('infile').addEventListener('change', |
| 104 uploadDidChange, | 108 uploadDidChange, |
| 105 false); | 109 false); |
| 106 } | 110 } |
| 107 | 111 |
| 108 function loadSuccess() { | 112 function loadSuccess() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 130 loadFromLocalStorage(); | 134 loadFromLocalStorage(); |
| 131 } | 135 } |
| 132 }; | 136 }; |
| 133 req.open('GET', PAK_FILE); | 137 req.open('GET', PAK_FILE); |
| 134 req.send(null); | 138 req.send(null); |
| 135 } | 139 } |
| 136 | 140 |
| 137 window.onload = function() { | 141 window.onload = function() { |
| 138 onLoad(); | 142 onLoad(); |
| 139 }; | 143 }; |
| OLD | NEW |