@@ -160,24 +160,20 @@ function saveConfig(config) {
160160
161161// Function to set up the development environment
162162async function setupEnvironment ( isManualSetup = false ) {
163- // Create necessary directories
164163 ensureDirectoryExists ( toolsPath ) ;
165164 ensureDirectoryExists ( gccPath ) ;
166165 ensureDirectoryExists ( ps1SdkPath ) ;
167166 ensureDirectoryExists ( emulatorPath ) ;
168167 ensureDirectoryExists ( gdbPath ) ;
169168 ensureDirectoryExists ( templatesPath ) ;
170169
171- // Load current configuration
172170 const config = loadConfig ( ) ;
173171
174- // Check if tools are already included in the plugin
175172 const gccExists = fs . existsSync ( gccPath ) && fs . readdirSync ( gccPath ) . length > 0 ;
176173 const ps1SdkExists = fs . existsSync ( ps1SdkPath ) && fs . readdirSync ( ps1SdkPath ) . length > 0 ;
177174 const emulatorExists = fs . existsSync ( emulatorPath ) && fs . readdirSync ( emulatorPath ) . length > 0 ;
178175 const gdbExists = fs . existsSync ( gdbPath ) && fs . readdirSync ( gdbPath ) . length > 0 ;
179176
180- // If all tools are included, mark them as installed
181177 if ( gccExists && ps1SdkExists && emulatorExists && gdbExists ) {
182178 config . tools . gcc . installed = true ;
183179 config . tools . ps1sdk . installed = true ;
@@ -189,10 +185,8 @@ async function setupEnvironment(isManualSetup = false) {
189185 return ;
190186 }
191187
192- // Download missing tools
193188 let downloadSuccess = true ;
194189
195- // Show a single notification for all downloads
196190 vscode . window . showInformationMessage ( 'Downloading required files...' ) ;
197191
198192 if ( ! gccExists ) {
@@ -218,7 +212,6 @@ async function setupEnvironment(isManualSetup = false) {
218212 if ( success ) {
219213 config . tools . emulator . installed = true ;
220214 } else {
221- // Emulator is optional, so don't fail if it can't be downloaded
222215 vscode . window . showWarningMessage ( 'Failed to download PlayStation 1 emulator, but it is optional.' ) ;
223216 }
224217 }
@@ -228,12 +221,10 @@ async function setupEnvironment(isManualSetup = false) {
228221 if ( success ) {
229222 config . tools . gdb = { installed : true } ;
230223 } else {
231- // GDB is optional for basic usage, so don't fail if it can't be downloaded
232224 vscode . window . showWarningMessage ( 'Failed to download GDB Multiarch debugger, but it is optional for basic usage.' ) ;
233225 }
234226 }
235227
236- // Save the configuration
237228 saveConfig ( config ) ;
238229
239230 if ( downloadSuccess ) {
@@ -290,43 +281,34 @@ async function createHelloWorld() {
290281// Function to build the project
291282async function buildProject ( ) {
292283 try {
293- // Get the current workspace folder
294284 const workspaceFolder = vscode . workspace . workspaceFolders [ 0 ] ;
295285 if ( ! workspaceFolder ) {
296286 throw new Error ( 'No workspace folder open' ) ;
297287 }
298288
299289 const projectPath = workspaceFolder . uri . fsPath ;
300290
301- // Check if Makefile exists
302291 const makefilePath = path . join ( projectPath , 'Makefile' ) ;
303292 if ( ! fs . existsSync ( makefilePath ) ) {
304293 throw new Error ( 'Makefile not found in the project directory' ) ;
305294 }
306295
307- // Get the paths to the tools
308296 const gccBinPath = path . join ( gccPath , 'bin' ) ;
309297 const sdkBinPath = path . join ( ps1SdkPath , 'bin' ) ;
310298
311- // Check if setup.mk exists and update it
312299 const setupMkPath = path . join ( projectPath , 'setup.mk' ) ;
313300 await updatePathsInFile ( setupMkPath ) ;
314301
315- // Update launch.json with correct paths and target
316302 await updateLaunchJson ( projectPath ) ;
317303
318- // Create a terminal and run make
319304 const terminal = vscode . window . createTerminal ( 'PS1 Build' ) ;
320305 terminal . show ( ) ;
321306
322- // Construct the PATH environment variable based on the platform
323307 let pathEnv ;
324308 if ( process . platform === 'win32' ) {
325- // Windows - PowerShell compatible command
326309 pathEnv = `$env:PATH = "${ gccBinPath . replace ( / \\ / g, '\\' ) } ;${ sdkBinPath . replace ( / \\ / g, '\\' ) } ;$env:PATH";` ;
327310 terminal . sendText ( `cd "${ projectPath . replace ( / \\ / g, '\\' ) } "; ${ pathEnv } make` ) ;
328311 } else {
329- // Unix-like systems (Linux, macOS)
330312 pathEnv = `PATH="${ gccBinPath } :${ sdkBinPath } :$PATH"` ;
331313 terminal . sendText ( `cd "${ projectPath } " && ${ pathEnv } make` ) ;
332314 }
@@ -338,43 +320,34 @@ async function buildProject() {
338320// Function to run the emulator
339321async function runEmulator ( ) {
340322 try {
341- // Get the current workspace folder
342323 const workspaceFolder = vscode . workspace . workspaceFolders [ 0 ] ;
343324 if ( ! workspaceFolder ) {
344325 throw new Error ( 'No workspace folder open' ) ;
345326 }
346-
327+
347328 const projectPath = workspaceFolder . uri . fsPath ;
348-
349- // Check if Makefile exists
329+
350330 const makefilePath = path . join ( projectPath , 'Makefile' ) ;
351331 if ( ! fs . existsSync ( makefilePath ) ) {
352332 throw new Error ( 'Makefile not found in the project directory' ) ;
353333 }
354-
355- // Get the paths to the tools
334+
356335 const gccBinPath = path . join ( gccPath , 'bin' ) ;
357336 const sdkBinPath = path . join ( ps1SdkPath , 'bin' ) ;
358-
359- // Check if setup.mk exists and update it
337+
360338 const setupMkPath = path . join ( projectPath , 'setup.mk' ) ;
361339 await updatePathsInFile ( setupMkPath ) ;
362340
363- // Update launch.json with correct paths and target
364341 await updateLaunchJson ( projectPath ) ;
365342
366- // Create a terminal and run make
367- const terminal = vscode . window . createTerminal ( 'PS1 Emulator' ) ;
343+ const terminal = vscode . window . createTerminal ( 'PS1 Run' ) ;
368344 terminal . show ( ) ;
369-
370- // Construct the PATH environment variable based on the platform
345+
371346 let pathEnv ;
372347 if ( process . platform === 'win32' ) {
373- // Windows - PowerShell compatible command
374348 pathEnv = `$env:PATH = "${ gccBinPath . replace ( / \\ / g, '\\' ) } ;${ sdkBinPath . replace ( / \\ / g, '\\' ) } ;$env:PATH";` ;
375349 terminal . sendText ( `cd "${ projectPath . replace ( / \\ / g, '\\' ) } "; ${ pathEnv } make run` ) ;
376350 } else {
377- // Unix-like systems (Linux, macOS)
378351 pathEnv = `PATH="${ gccBinPath } :${ sdkBinPath } :$PATH"` ;
379352 terminal . sendText ( `cd "${ projectPath } " && ${ pathEnv } make run` ) ;
380353 }
@@ -386,43 +359,34 @@ async function runEmulator() {
386359// Function to generate ISO
387360async function generateISO ( ) {
388361 try {
389- // Get the current workspace folder
390362 const workspaceFolder = vscode . workspace . workspaceFolders [ 0 ] ;
391363 if ( ! workspaceFolder ) {
392364 throw new Error ( 'No workspace folder open' ) ;
393365 }
394-
366+
395367 const projectPath = workspaceFolder . uri . fsPath ;
396-
397- // Check if Makefile exists
368+
398369 const makefilePath = path . join ( projectPath , 'Makefile' ) ;
399370 if ( ! fs . existsSync ( makefilePath ) ) {
400371 throw new Error ( 'Makefile not found in the project directory' ) ;
401372 }
402-
403- // Get the paths to the tools
373+
404374 const gccBinPath = path . join ( gccPath , 'bin' ) ;
405375 const sdkBinPath = path . join ( ps1SdkPath , 'bin' ) ;
406-
407- // Check if setup.mk exists and update it
376+
408377 const setupMkPath = path . join ( projectPath , 'setup.mk' ) ;
409378 await updatePathsInFile ( setupMkPath ) ;
410379
411- // Update launch.json with correct paths and target
412380 await updateLaunchJson ( projectPath ) ;
413381
414- // Create a terminal and run make
415- const terminal = vscode . window . createTerminal ( 'PS1 ISO Generation' ) ;
382+ const terminal = vscode . window . createTerminal ( 'PS1 ISO' ) ;
416383 terminal . show ( ) ;
417-
418- // Construct the PATH environment variable based on the platform
384+
419385 let pathEnv ;
420386 if ( process . platform === 'win32' ) {
421- // Windows - PowerShell compatible command
422387 pathEnv = `$env:PATH = "${ gccBinPath . replace ( / \\ / g, '\\' ) } ;${ sdkBinPath . replace ( / \\ / g, '\\' ) } ;$env:PATH";` ;
423388 terminal . sendText ( `cd "${ projectPath . replace ( / \\ / g, '\\' ) } "; ${ pathEnv } make iso` ) ;
424389 } else {
425- // Unix-like systems (Linux, macOS)
426390 pathEnv = `PATH="${ gccBinPath } :${ sdkBinPath } :$PATH"` ;
427391 terminal . sendText ( `cd "${ projectPath } " && ${ pathEnv } make iso` ) ;
428392 }
@@ -490,10 +454,8 @@ async function downloadAndExtractTool(toolName) {
490454 try {
491455 const toolsUrls = JSON . parse ( fs . readFileSync ( path . join ( extensionPath , 'tools-urls.json' ) , 'utf8' ) ) ;
492456
493- // Get the current platform
494457 const platform = process . platform ;
495458
496- // Find the tool for the current platform
497459 let tool = null ;
498460 for ( const [ key , value ] of Object . entries ( toolsUrls ) ) {
499461 if ( key === toolName || key . startsWith ( toolName + '_' ) ) {
@@ -512,28 +474,21 @@ async function downloadAndExtractTool(toolName) {
512474 const extractPath = path . join ( extensionPath , tool . extractPath ) ;
513475 const checkFile = path . join ( extractPath , tool . checkFile ) ;
514476
515- // Create the directory if it doesn't exist
516477 if ( ! fs . existsSync ( extractPath ) ) {
517478 fs . mkdirSync ( extractPath , { recursive : true } ) ;
518479 }
519480
520- // Download the tool
521481 const response = await axios . get ( url , { responseType : 'arraybuffer' } ) ;
522482
523- // Extract the tool
524- // Check if the file is a DMG (macOS disk image)
525483 if ( url . endsWith ( '.dmg' ) ) {
526- // Save the DMG file
527484 const dmgPath = path . join ( os . tmpdir ( ) , `${ toolName } .dmg` ) ;
528485 fs . writeFileSync ( dmgPath , Buffer . from ( response . data ) ) ;
529486
530- // Mount the DMG
531487 const mountPoint = path . join ( os . tmpdir ( ) , `${ toolName } _mount` ) ;
532488 if ( ! fs . existsSync ( mountPoint ) ) {
533489 fs . mkdirSync ( mountPoint , { recursive : true } ) ;
534490 }
535491
536- // Use hdiutil to mount the DMG
537492 await new Promise ( ( resolve , reject ) => {
538493 exec ( `hdiutil attach "${ dmgPath } " -mountpoint "${ mountPoint } "` , ( error ) => {
539494 if ( error ) {
@@ -544,7 +499,6 @@ async function downloadAndExtractTool(toolName) {
544499 } ) ;
545500 } ) ;
546501
547- // Copy the contents to the extract path
548502 await new Promise ( ( resolve , reject ) => {
549503 exec ( `cp -R "${ mountPoint } /"* "${ extractPath } /"` , ( error ) => {
550504 if ( error ) {
@@ -555,7 +509,6 @@ async function downloadAndExtractTool(toolName) {
555509 } ) ;
556510 } ) ;
557511
558- // Unmount the DMG
559512 await new Promise ( ( resolve , reject ) => {
560513 exec ( `hdiutil detach "${ mountPoint } "` , ( error ) => {
561514 if ( error ) {
@@ -566,34 +519,27 @@ async function downloadAndExtractTool(toolName) {
566519 } ) ;
567520 } ) ;
568521
569- // Remove the DMG file
570522 fs . unlinkSync ( dmgPath ) ;
571523 } else {
572- // Special handling for PSN00B_SDK which contains a folder structure
573524 if ( toolName . includes ( 'psn00b_sdk' ) ) {
574- // Create a temporary directory for extraction
575525 const tempExtractPath = path . join ( os . tmpdir ( ) , `${ toolName } _temp` ) ;
576526 if ( fs . existsSync ( tempExtractPath ) ) {
577527 fse . removeSync ( tempExtractPath ) ;
578528 }
579529 fs . mkdirSync ( tempExtractPath , { recursive : true } ) ;
580530
581- // Extract ZIP file to temp location
582531 const zip = new AdmZip ( Buffer . from ( response . data ) ) ;
583532 zip . extractAllTo ( tempExtractPath , true ) ;
584533
585- // Clear the target directory
586534 if ( fs . existsSync ( extractPath ) ) {
587535 fse . emptyDirSync ( extractPath ) ;
588536 } else {
589537 fs . mkdirSync ( extractPath , { recursive : true } ) ;
590538 }
591539
592- // Find the SDK folder in the temp directory
593540 const tempFiles = fs . readdirSync ( tempExtractPath ) ;
594541 let sdkFolderName = null ;
595542
596- // Look for the main SDK folder (usually named PSn00bSDK or similar)
597543 for ( const file of tempFiles ) {
598544 const filePath = path . join ( tempExtractPath , file ) ;
599545 if ( fs . statSync ( filePath ) . isDirectory ( ) &&
@@ -604,29 +550,23 @@ async function downloadAndExtractTool(toolName) {
604550 }
605551
606552 if ( sdkFolderName ) {
607- // Move the SDK folder contents to the target location
608553 const sdkFolderPath = path . join ( tempExtractPath , sdkFolderName ) ;
609554 fse . copySync ( sdkFolderPath , extractPath ) ;
610555 } else {
611- // If no specific SDK folder found, copy everything
612556 fse . copySync ( tempExtractPath , extractPath ) ;
613557 }
614558
615- // Clean up temp directory
616559 fse . removeSync ( tempExtractPath ) ;
617560 } else {
618- // Extract ZIP file directly for other tools
619561 const zip = new AdmZip ( Buffer . from ( response . data ) ) ;
620562 zip . extractAllTo ( extractPath , true ) ;
621563 }
622564 }
623565
624- // Check if the extraction was successful
625566 if ( ! fs . existsSync ( checkFile ) ) {
626567 throw new Error ( `Failed to extract ${ toolName } . ${ checkFile } not found.` ) ;
627568 }
628569
629- // Make the file executable
630570 if ( platform !== 'win32' ) {
631571 await new Promise ( ( resolve , reject ) => {
632572 exec ( `chmod +x "${ checkFile } "` , ( error ) => {
@@ -641,7 +581,6 @@ async function downloadAndExtractTool(toolName) {
641581
642582 return true ;
643583 } catch ( error ) {
644- console . error ( error ) ;
645584 return false ;
646585 }
647586}
0 commit comments