this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

copy baserom to nix store

+119 -76
+16 -35
src/main/java/app/Directories.java
··· 20 20 21 21 LOGS (Root.STATE, "/logs/"), 22 22 TEMP (Root.STATE, "/temp/"), 23 + BASEROM (Root.STATE, "/baserom/"), 23 24 24 25 //======================================================================================= 25 26 // Directories contain dumped content needed for Star Rod to function 26 27 // These should all eventually become unnecessary and be removed 27 28 28 - DUMP_WORLD (Root.DUMP, "/world/"), 29 + DUMP (Root.STATE, "/dump/"), 30 + DUMP_WORLD (Root.STATE, DUMP, "/world/"), 29 31 30 - DUMP_ENTITY (Root.DUMP, DUMP_WORLD, "/entity/"), 31 - DUMP_ENTITY_RAW (Root.DUMP, DUMP_ENTITY, "/raw/"), 32 - DUMP_ENTITY_SRC (Root.DUMP, DUMP_ENTITY, "/src/"), 32 + DUMP_ENTITY (Root.STATE, DUMP_WORLD, "/entity/"), 33 + DUMP_ENTITY_RAW (Root.STATE, DUMP_ENTITY, "/raw/"), 34 + DUMP_ENTITY_SRC (Root.STATE, DUMP_ENTITY, "/src/"), 33 35 34 - DUMP_MSG (Root.DUMP, "/message/"), 35 - DUMP_MSG_FONT (Root.DUMP, DUMP_MSG, "/font/"), 36 - DUMP_FONT_STD (Root.DUMP, DUMP_MSG_FONT, "/normal/"), 37 - DUMP_FONT_STD_PAL (Root.DUMP, DUMP_FONT_STD, "/palette/"), 38 - DUMP_FONT_CR1 (Root.DUMP, DUMP_MSG_FONT, "/credits-title/"), 39 - DUMP_FONT_CR1_PAL (Root.DUMP, DUMP_FONT_CR1, "/palette/"), 40 - DUMP_FONT_CR2 (Root.DUMP, DUMP_MSG_FONT, "/credits-name/"), 41 - DUMP_FONT_CR2_PAL (Root.DUMP, DUMP_FONT_CR2, "/palette/"), 36 + DUMP_MSG (Root.STATE, DUMP, "/message/"), 37 + DUMP_MSG_FONT (Root.STATE, DUMP_MSG, "/font/"), 38 + DUMP_FONT_STD (Root.STATE, DUMP_MSG_FONT, "/normal/"), 39 + DUMP_FONT_STD_PAL (Root.STATE, DUMP_FONT_STD, "/palette/"), 40 + DUMP_FONT_CR1 (Root.STATE, DUMP_MSG_FONT, "/credits-title/"), 41 + DUMP_FONT_CR1_PAL (Root.STATE, DUMP_FONT_CR1, "/palette/"), 42 + DUMP_FONT_CR2 (Root.STATE, DUMP_MSG_FONT, "/credits-name/"), 43 + DUMP_FONT_CR2_PAL (Root.STATE, DUMP_FONT_CR2, "/palette/"), 42 44 43 45 //======================================================================================= 44 46 // Directories relative to the current project ··· 134 136 135 137 private enum Root 136 138 { 137 - NONE, DUMP, PROJECT, CONFIG, STATE, ENGINE 139 + NONE, PROJECT, CONFIG, STATE, ENGINE 138 140 } 139 141 140 142 private static String getRootPath(Root root) ··· 142 144 switch (root) { 143 145 case NONE: 144 146 return Environment.getWorkingDirectory().getAbsolutePath(); 145 - case DUMP: 146 - return dumpPath; 147 147 case PROJECT: 148 148 return projPath; 149 149 case CONFIG: ··· 157 157 return null; 158 158 } 159 159 160 - private static String dumpPath = null; 161 160 private static String projPath = null; 162 161 163 - public static void setDumpDirectory(String path) 164 - { 165 - if (path.contains("\\")) 166 - path = path.replaceAll("\\\\", "/"); 167 - if (path.endsWith("/")) 168 - path = path.substring(0, path.length() - 1); 169 - 170 - dumpPath = path; 171 - } 172 - 173 - public static String getDumpPath() 174 - { 175 - return dumpPath; 176 - } 177 - 178 162 public static void setProjectDirectory(String path) 179 163 { 180 164 if (path.contains("\\")) ··· 188 172 189 173 public static void createDumpDirectories() throws IOException 190 174 { 191 - if (dumpPath == null) 192 - throw new IOException("Dump directory is not set."); 193 - 194 175 for (Directories dir : Directories.values()) { 195 - if (dir.root == Root.DUMP && !dir.optional) 176 + if (dir.root == Root.STATE && dir.path.startsWith("/dump/") && !dir.optional) 196 177 FileUtils.forceMkdir(dir.toFile()); 197 178 } 198 179 }
+17 -21
src/main/java/app/Environment.java
··· 102 102 103 103 private static String gameVersion = ""; 104 104 105 - private static File usBaseRom; 105 + private static final File usBaseRom = Directories.BASEROM.file("papermario.us.z64"); 106 106 private static ByteBuffer romBytes; 107 107 108 108 public static List<File> assetDirectories; ··· 268 268 ProjectListing listing = chooseProject(); 269 269 if (listing == null) 270 270 exit(); 271 - LoadingBar.show("Loading " + listing.getName(), Priority.MILESTONE, false); 272 271 boolean validProject = loadProject(listing); 273 272 if (!validProject) 274 273 exit(1); ··· 531 530 532 531 Directories.setProjectDirectory(project.getPath()); 533 532 final Engine engine = project.getEngine(); 534 - Directories.setDumpDirectory(engine.getDumpDir().getAbsolutePath()); 535 533 536 - usBaseRom = engine.getBaseRom(); 537 - if (!usBaseRom.exists()) { 538 - promptForBaserom(); 539 - if (!usBaseRom.exists()) 534 + if (!usBaseRom.exists()) 535 + if (!promptForBaserom(engine)) 540 536 return false; 541 - } 537 + 538 + LoadingBar.show("Loading project", Priority.MILESTONE, true); 542 539 543 540 try { 544 541 engine.splitAssets(); ··· 615 612 } 616 613 617 614 /** 618 - * Prompts the user to select a baserom file, validates it, and copies 619 - * it to the appropriate location. 615 + * Prompts the user to select a ROM, validates it, and installs it in the BuildEnvironment. 620 616 */ 621 - public static void promptForBaserom() 617 + public static boolean promptForBaserom(Engine engine) 622 618 { 623 619 OpenFileChooser chooser = new OpenFileChooser( 624 620 null, "Select Paper Mario (US) ROM", "N64 ROM", "z64", "n64", "v64"); 625 621 626 622 if (chooser.prompt() != ChooseDialogResult.APPROVE) 627 - return; 623 + return false; 628 624 629 625 File selected = chooser.getSelectedFile(); 630 626 if (selected == null) 631 - return; 627 + return false; 632 628 633 629 try { 634 630 File validated = RomValidator.validateROM(selected); 635 631 if (validated == null) 636 - return; 632 + return false; 637 633 638 - // Copy to target location 639 634 FileUtils.copyFile(validated, usBaseRom); 640 - Logger.log("Baserom installed to " + usBaseRom.getAbsolutePath()); 635 + engine.getBuildEnvironment().installBaserom(validated); 636 + return true; 641 637 } 642 - catch (IOException e) { 638 + catch (IOException | BuildException e) { 643 639 Logger.printStackTrace(e); 644 - showErrorMessage("ROM Copy Error", "Failed to copy ROM: %s", e.getMessage()); 640 + showErrorMessage("ROM Installation Error", "Failed to install ROM: %s", e.getMessage()); 641 + return false; 645 642 } 646 643 } 647 644 648 645 /** 649 646 * Ensures the dump directory is extracted. If it doesn't exist, 650 647 * extracts from the baserom (prompting for the ROM if needed). 651 - * Sets usBaseRom and dumpPath as side effects when the user provides a ROM. 652 648 * @return true if dump is available, false if user cancelled or extraction failed 653 649 */ 654 650 public static boolean ensureDumpExtracted() throws IOException 655 651 { 656 - String dumpPath = Directories.getDumpPath(); 652 + File dumpDir = Directories.DUMP.toFile(); 657 653 658 - if (dumpPath == null || !(new File(dumpPath).exists())) { 654 + if (!dumpDir.exists()) { 659 655 // Need baserom to create dump 660 656 if (usBaseRom == null || !usBaseRom.exists()) { 661 657 Logger.logError("Cannot extract dump: baserom not found");
-7
src/main/java/app/RomValidator.java
··· 76 76 boolean x64 = (crc1 == CRC1_X64 && crc2 == CRC2_X64); 77 77 78 78 if (v64 || n64 || x64) { 79 - // just need to byteswap 80 - SwingUtils.getMessageDialog() 81 - .setTitle("ROM Validation Warning") 82 - .setMessage("Selected ROM has incorrect byte order.", "A corrected copy will be made.") 83 - .setMessageType(JOptionPane.WARNING_MESSAGE) 84 - .show(); 85 - 86 79 pleaseWait.setVisible(true); 87 80 88 81 String path = f.getAbsolutePath();
+1 -1
src/main/java/app/StarRodMain.java
··· 551 551 552 552 private static final void trySetIcon(AbstractButton button, ExpectedAsset asset) 553 553 { 554 - if (Directories.getDumpPath() == null || !(new File(Directories.getDumpPath())).exists()) { 554 + if (!Directories.DUMP.toFile().exists()) { 555 555 Logger.log("Dump directory could not be found."); 556 556 SwingUtils.addBorderPadding(button); 557 557 return;
+10
src/main/java/project/engine/BuildEnvironment.java
··· 54 54 */ 55 55 void gitCheckout(File dir, String ref, BuildOutputListener listener) throws IOException; 56 56 57 + // --- Baserom management --- 58 + 59 + /** 60 + * Installs the base ROM into /tmp as papermario.us.z64 and adds it to the Nix store. 61 + * @param sourceRom The source ROM file to install 62 + * @throws BuildException If the installation fails 63 + * @throws IOException If an I/O error occurs 64 + */ 65 + void installBaserom(File sourceRom) throws BuildException, IOException; 66 + 57 67 // --- Build operations --- 58 68 59 69 /**
-12
src/main/java/project/engine/Engine.java
··· 18 18 { 19 19 private static final String BARE_REPO_NAME = "papermario-dx.git"; 20 20 private static final String REPO_URL = "https://github.com/bates64/papermario-dx.git"; 21 - private static final String BASEROM_PATH = "ver/us/baserom.z64"; 22 - private static final String DUMP_PATH = "ver/us/build/star-rod-dump"; 23 21 24 22 /** If a project provides a custom engine, it should be a git repo at this directory. */ 25 23 public static final String PROJECT_ENGINE_PATH = "papermario-dx"; ··· 87 85 public File getDirectory() 88 86 { 89 87 return directory; 90 - } 91 - 92 - public File getBaseRom() 93 - { 94 - return new File(directory, BASEROM_PATH); 95 - } 96 - 97 - public File getDumpDir() 98 - { 99 - return new File(directory, DUMP_PATH); 100 88 } 101 89 102 90 public String getRef()
+41
src/main/java/project/engine/NixEnvironment.java
··· 62 62 } 63 63 } 64 64 65 + // --- Baserom management --- 66 + 67 + @Override 68 + public void installBaserom(File sourceRom) throws BuildException, IOException 69 + { 70 + if (!sourceRom.exists()) { 71 + throw new IOException("Source ROM does not exist: " + sourceRom); 72 + } 73 + 74 + // Check if ROM is already in Nix store 75 + String expectedHash = "9ec6d2a5c2fca81ab86312328779fd042b5f3b920bf65df9f6b87b376883cb5b"; 76 + String[] checkCmd = new String[] { 77 + "bash", "-c", 78 + "test -e $(nix-store --print-fixed-path sha256 " + expectedHash + " papermario.us.z64)" 79 + }; 80 + 81 + ProcessRunner.ProcessResult checkResult = runner.run(checkCmd, null, BuildOutputListener.toLogger()); 82 + if (checkResult.isSuccess()) { 83 + return; // Already in store 84 + } 85 + 86 + File targetRom = new File("/tmp/papermario.us.z64"); 87 + 88 + // Copy ROM to /tmp 89 + java.nio.file.Files.copy( 90 + sourceRom.toPath(), 91 + targetRom.toPath(), 92 + java.nio.file.StandardCopyOption.REPLACE_EXISTING 93 + ); 94 + 95 + // Add to Nix store 96 + String[] cmd = new String[] { 97 + "nix-store", "--add-fixed", "sha256", targetRom.getAbsolutePath() 98 + }; 99 + 100 + ProcessRunner.ProcessResult result = runner.run(cmd, null, BuildOutputListener.toLogger()); 101 + if (!result.isSuccess()) { 102 + throw new BuildException("Failed to add ROM to Nix store (exit code " + result.getExitCode() + ")"); 103 + } 104 + } 105 + 65 106 // --- Build operations --- 66 107 67 108 @Override
+34
src/main/java/project/engine/WslNixOsEnvironment.java
··· 115 115 } 116 116 } 117 117 118 + // --- Baserom management --- 119 + 120 + @Override 121 + public void installBaserom(File sourceRom) throws BuildException, IOException 122 + { 123 + if (!sourceRom.exists()) { 124 + throw new IOException("Source ROM does not exist: " + sourceRom); 125 + } 126 + 127 + // Check if ROM is already in Nix store 128 + String expectedHash = "9ec6d2a5c2fca81ab86312328779fd042b5f3b920bf65df9f6b87b376883cb5b"; 129 + String[] checkCmd = new String[] { 130 + "wsl", "-d", DISTRO_NAME, "bash", "-c", 131 + "test -e $(nix-store --print-fixed-path sha256 " + expectedHash + " papermario.us.z64)" 132 + }; 133 + 134 + ProcessRunner.ProcessResult checkResult = runner.run(checkCmd, null, BuildOutputListener.toLogger()); 135 + if (checkResult.isSuccess()) { 136 + return; // Already in store 137 + } 138 + 139 + // Copy ROM from Windows to WSL /tmp and add to Nix store 140 + String wslSourcePath = convertToWslPath(sourceRom); 141 + String[] cmd = new String[] { 142 + "wsl", "-d", DISTRO_NAME, "bash", "-c", 143 + "cp " + wslSourcePath + " /tmp/papermario.us.z64 && nix-store --add-fixed sha256 /tmp/papermario.us.z64" 144 + }; 145 + 146 + ProcessRunner.ProcessResult result = runner.run(cmd, null, BuildOutputListener.toLogger()); 147 + if (!result.isSuccess()) { 148 + throw new BuildException("Failed to add ROM to Nix store (exit code " + result.getExitCode() + ")"); 149 + } 150 + } 151 + 118 152 // --- Build operations --- 119 153 120 154 @Override