diff --git a/README.md b/README.md index 8f4e817..d041158 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ OPL-compatible PS2 tool for making split files. Sort of ul.cfg manager or USBUtil. +![Application screenshot](screenshots/1.png) + #### Let's stay in touch GitHubs are arising and passing, cozy mirrors are eternal: https://git.redrise.ru/desu/Tihwin diff --git a/pom.xml b/pom.xml index d88ae5d..3e639b6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,15 +4,15 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - loper + ru.redrise Tihwin Tihwin - 1.0 + 1.1 https://github.com/developersu/${project.artifactId}/ - NS Atmosphere dongle flash tool + OPL-compatible PS2 tool for making split files. Sort of ul.cfg manager or USBUtil. 2022 @@ -36,7 +36,7 @@ Developer +3 - https://developersu.blogspot.com/ + https://redrise.ru/ diff --git a/screenshots/1.png b/screenshots/1.png new file mode 100644 index 0000000..1cb2756 Binary files /dev/null and b/screenshots/1.png differ diff --git a/src/main/java/tihwin/MainAppUi.java b/src/main/java/tihwin/MainAppUi.java index 49be658..821d74c 100644 --- a/src/main/java/tihwin/MainAppUi.java +++ b/src/main/java/tihwin/MainAppUi.java @@ -72,7 +72,10 @@ public class MainAppUi extends JFrame { destinationSelectBtn.addActionListener(actionEvent -> destinationSelectEventHandler()); convertBtn.addActionListener(actionEvent -> convertButtonAction()); ((AbstractDocument) titleField.getDocument()).setDocumentFilter(new TitleFieldFilter()); - + if (Settings.INSTANCE.getDvdSelected()) + DVDRadioButton.setSelected(true); + else + CDRadioButton.setSelected(true); recentRomLocation = Settings.INSTANCE.getRomLocation(); destinationDirectoryLbl.setText(FilesHelper.getRealFolder(Settings.INSTANCE.getDestination())); @@ -90,6 +93,7 @@ public class MainAppUi extends JFrame { public void windowClosing(WindowEvent windowEvent) { Settings.INSTANCE.setRomLocation(recentRomLocation); Settings.INSTANCE.setDestination(destinationDirectoryLbl.getText()); + Settings.INSTANCE.setDvdSelected(DVDRadioButton.isSelected()); } @Override diff --git a/src/main/java/tihwin/Settings.java b/src/main/java/tihwin/Settings.java index 5ae88c3..87aa2dd 100644 --- a/src/main/java/tihwin/Settings.java +++ b/src/main/java/tihwin/Settings.java @@ -35,6 +35,9 @@ public class Settings { public String getDestination(){ return preferences.get("destination", System.getProperty("user.home")); } + public boolean getDvdSelected(){ + return preferences.getBoolean("dvd_selected", true); + } public void setDestination(String location){ preferences.put("destination", location); @@ -42,4 +45,7 @@ public class Settings { public void setRomLocation(String location){ preferences.put("rom_location", location); } + public void setDvdSelected(boolean value) { + preferences.putBoolean("dvd_selected", value); + } } diff --git a/src/main/java/tihwin/ul/UlConfiguration.java b/src/main/java/tihwin/ul/UlConfiguration.java index 0a85775..27f5578 100644 --- a/src/main/java/tihwin/ul/UlConfiguration.java +++ b/src/main/java/tihwin/ul/UlConfiguration.java @@ -20,6 +20,7 @@ */ package tihwin.ul; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -85,14 +86,14 @@ public class UlConfiguration { public byte[] generateUlConfig(){ ByteBuffer byteBuffer = ByteBuffer.allocate(0x40); byteBuffer.put(title.getBytes(StandardCharsets.US_ASCII)); - byteBuffer.position(32); + ((Buffer) byteBuffer).position(32); byteBuffer.put(("ul."+publisherTitle).getBytes()); - byteBuffer.position(32+15); + ((Buffer) byteBuffer).position(32+15); byteBuffer.put(chunksCount); byteBuffer.put(cdDvdFlag); - byteBuffer.position(53); + ((Buffer) byteBuffer).position(53); byteBuffer.put((byte) 0x8); // weird. no idea why it's here - byteBuffer.flip(); + ((Buffer) byteBuffer).flip(); return byteBuffer.array(); } } diff --git a/src/main/java/tihwin/ul/UlMaker.java b/src/main/java/tihwin/ul/UlMaker.java index fe87aaa..74f4446 100644 --- a/src/main/java/tihwin/ul/UlMaker.java +++ b/src/main/java/tihwin/ul/UlMaker.java @@ -69,35 +69,44 @@ public class UlMaker implements Runnable{ safeShutdown(); } catch (Exception e){ - updater.setStatus(resourceBundle.getString("FailedText")+" "+e.getMessage()); e.printStackTrace(); + if (! interrupted()) { + updater.setStatus(resourceBundle.getString("FailedText") + " " + e.getMessage()); + return; + } + safeShutdown(); } finally { updater.close(); } } - private void safeShutdown(){ - boolean isDeleted = true; - for (int i = 0; i < ulConfiguration.getChunksCount(); i++) { - File chunkFile = new File(String.format(locationPattern, i)); - if (chunkFile.exists()) - isDeleted &= chunkFile.delete(); - } + private void safeShutdown() { + updater.setStatus(resourceBundle.getString("PleaseWaitText")); + try{ + boolean isDeleted = true; + for (int i = 0; i < ulConfiguration.getChunksCount(); i++) { + isDeleted &= Files.deleteIfExists(Paths.get(String.format(locationPattern, i))); + } - if (isDeleted) - updater.setStatus(resourceBundle.getString("InterruptedAndFilesDeletedText")); - else - updater.setStatus(resourceBundle.getString("InterruptedAndFilesNotDeletedText")); + if (isDeleted) + updater.setStatus(resourceBundle.getString("InterruptedAndFilesDeletedText")); + else + updater.setStatus(resourceBundle.getString("InterruptedAndFilesNotDeletedText")); + } + catch (Exception e){ + updater.setStatus(resourceBundle.getString("FailedText") + " " + e.getMessage()); + e.printStackTrace(); + } } private void makeUlFile() throws Exception { byte[] config = ulConfiguration.generateUlConfig(); - RandomAccessFile raf = new RandomAccessFile(ulLocation+File.separator+"ul.cfg", "rw"); - raf.seek(raf.length()); - raf.write(config); - raf.close(); + try (RandomAccessFile raf = new RandomAccessFile(ulLocation+File.separator+"ul.cfg", "rw")){ + raf.seek(raf.length()); + raf.write(config); + } } private void splitToChunks() throws Exception{ @@ -109,28 +118,27 @@ public class UlMaker implements Runnable{ main_loop: for (int chunkNumber = 0; ; chunkNumber++){ String pathname = String.format(locationPattern, chunkNumber); - BufferedOutputStream fragmentBos = new BufferedOutputStream(Files.newOutputStream(Paths.get(pathname))); + try (BufferedOutputStream fragmentBos = new BufferedOutputStream(Files.newOutputStream(Paths.get(pathname)))){ + long counter = 0; - long counter = 0; + while (counter < 256){ + byte[] chunk = new byte[4194304]; - while (counter < 256){ - byte[] chunk = new byte[4194304]; + if ((readBytesCount = bis.read(chunk)) < 4194304){ + if (readBytesCount > 0) + fragmentBos.write(chunk, 0, readBytesCount); + fragmentBos.close(); + updater.updateProgressBySize(readBytesCount); + break main_loop; + } + if (interrupted()) + throw new InterruptedException(); - if ((readBytesCount = bis.read(chunk)) < 4194304){ - if (readBytesCount > 0) - fragmentBos.write(chunk, 0, readBytesCount); - fragmentBos.close(); + fragmentBos.write(chunk); + counter++; updater.updateProgressBySize(readBytesCount); - break main_loop; } - if (interrupted()) - throw new InterruptedException(); - - fragmentBos.write(chunk); - counter++; - updater.updateProgressBySize(readBytesCount); } - fragmentBos.close(); } } } diff --git a/src/main/resources/locale.properties b/src/main/resources/locale.properties index 0c4cba1..e61e29a 100644 --- a/src/main/resources/locale.properties +++ b/src/main/resources/locale.properties @@ -21,3 +21,4 @@ ISO_NotSupportedCdDvd=Not supported CD/DVD format ISO_CantReadRootDescriptor=Can't read CD/DVD directory entry for the root directory ISO_NoSystemCnf=SYSTEM.CNF not found in this CD/DVD. Is it a PS2 Disk? ISO_PublisherTitleNotFound=Title not found. SYSTEM.CNF file is next: +PleaseWaitText=Please wait while useless file fragments removing... diff --git a/src/main/resources/locale_ru_RU.properties b/src/main/resources/locale_ru_RU.properties index 3d162b9..918be85 100644 --- a/src/main/resources/locale_ru_RU.properties +++ b/src/main/resources/locale_ru_RU.properties @@ -21,3 +21,4 @@ ISO_NotSupportedCdDvd=\u041D\u0435\u043F\u043E\u0434\u0434\u0435\u0440\u0436\u04 ISO_CantReadRootDescriptor=\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u043F\u0440\u043E\u0447\u0435\u0441\u0442\u044C \u0437\u0430\u043F\u0438\u0441\u044C \u043A\u043E\u0440\u043D\u0435\u0432\u043E\u0433\u043E \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 CD/DVD \u0434\u0438\u0441\u043A\u0430 ISO_NoSystemCnf=\u041D\u0430 \u044D\u0442\u043E\u043C CD/DVD \u043D\u0435\u0442 \u0444\u0430\u0439\u043B\u0430 SYSTEM.CNF. \u042D\u0442\u043E \u0442\u043E\u0447\u043D\u043E \u0434\u0438\u0441\u043A \u0434\u043B\u044F PS2? ISO_PublisherTitleNotFound=\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u043E. SYSTEM.CNF \u0432\u044B\u0433\u043B\u044F\u0434\u0438\u0442 \u0442\u0430\u043A: +PleaseWaitText=\u041F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430, \u043F\u043E\u0434\u043E\u0436\u0434\u0438\u0442\u0435 \u043F\u043E\u043A\u0430 \u0443\u0434\u0430\u043B\u044F\u044E\u0442\u0441\u044F \u043D\u0435\u043D\u0443\u0436\u043D\u044B\u0435 \u0444\u0440\u0430\u0433\u043C\u0435\u043D\u0442\u044B \u0444\u0430\u0439\u043B\u0430...