Skip to content

Commit

Permalink
Implement FTP in emuiigen, other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Aug 20, 2023
1 parent b6fa7cb commit 3b0d98e
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 55 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@

.PHONY: all emuiibo sysmodule overlay emuiigen dist emuiibo-clean emuiigen-clean
.PHONY: all dev emuiibo emuiibo-dev sysmodule sysmodule-dev overlay emuiigen dist clean emuiibo-clean emuiigen-clean

# We need to provide a custom target triple since the official tier 3 one doesn't provide crypto support
TARGET_TRIPLE := aarch64-nintendo-switch-freestanding-crypto
PROGRAM_ID := 0100000000000352

all: emuiibo emuiigen

dev: emuiibo-dev emuiigen

clean: emuiibo-clean emuiigen-clean

emuiibo: sysmodule overlay dist

emuiibo-dev: sysmodule-dev overlay dist

sysmodule:
@cd emuiibo && cargo update && cargo nx build --release --target $(TARGET_TRIPLE).json

sysmodule-dev:
@cd emuiibo && cargo update && cargo nx build --target $(TARGET_TRIPLE).json

overlay:
@$(MAKE) -C overlay/

Expand All @@ -33,6 +44,4 @@ emuiibo-clean:
@$(MAKE) clean -C overlay/

emuiigen-clean:
@cd emuiigen && mvn clean

all: emuiibo emuiigen
@cd emuiigen && mvn clean
8 changes: 7 additions & 1 deletion emuiibo/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ pub enum VirtualAmiiboStatus {
Disconnected
}

pub const CURRENT_VERSION: Version = Version::from(1, 0, 0, true);
#[cfg(debug_assertions)]
pub const IS_DEV_BUILD: bool = true;

#[cfg(not(debug_assertions))]
pub const IS_DEV_BUILD: bool = false;

pub const CURRENT_VERSION: Version = Version::from(1, 0, 0, IS_DEV_BUILD);

static mut G_EMULATION_STATUS: sync::Locked<EmulationStatus> = sync::Locked::new(false, EmulationStatus::Off);
static mut G_ACTIVE_VIRTUAL_AMIIBO_STATUS: sync::Locked<VirtualAmiiboStatus> = sync::Locked::new(false, VirtualAmiiboStatus::Invalid);
Expand Down
7 changes: 6 additions & 1 deletion emuiigen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<groupId>com.xortroll.emuiibo.emuiigen</groupId>
<artifactId>emuiigen</artifactId>

<version>1.0.0-dev</version>
<version>1.0.0</version>
<name>emuiigen</name>

<properties>
Expand Down Expand Up @@ -104,6 +104,11 @@
<artifactId>commons-io</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Expand Down
44 changes: 31 additions & 13 deletions emuiigen/res/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
Expand Down Expand Up @@ -87,24 +88,29 @@
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" layoutX="409.0" layoutY="14.0" prefHeight="262.0" prefWidth="381.0" text="Customize it">
<TitledPane animated="false" layoutX="409.0" layoutY="14.0" prefHeight="240.0" prefWidth="382.0" text="Customize it">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="439.0" prefWidth="386.0">
<children>
<TextField fx:id="AmiiboNameText" layoutX="15.0" layoutY="14.0" prefHeight="28.0" prefWidth="346.0" promptText="Virtual amiibo name" />
<TextField fx:id="AmiiboDirectoryText" layoutX="15.0" layoutY="54.0" prefHeight="28.0" prefWidth="346.0" promptText="Directory name" />
<CheckBox fx:id="NameAsDirectoryNameCheck" layoutX="18.0" layoutY="87.0" mnemonicParsing="false" selected="true" text="Use name as directory name" />
<CheckBox fx:id="GenerateOneUseRandomUuidCheck" layoutX="18.0" layoutY="143.0" mnemonicParsing="false" text="Enable UUID randomization" />
<CheckBox fx:id="GenerateOneImageSaveCheck" layoutX="18.0" layoutY="198.0" mnemonicParsing="false" text="Save image" />
<CheckBox fx:id="GenerateOneUseRandomUuidCheck" layoutX="18.0" layoutY="133.0" mnemonicParsing="false" text="Enable UUID randomization" />
<CheckBox fx:id="GenerateOneImageSaveCheck" layoutX="18.0" layoutY="179.0" mnemonicParsing="false" text="Save image" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" layoutX="409.0" layoutY="291.0" prefHeight="85.0" prefWidth="383.0" text="Generate it">
<TitledPane animated="false" layoutX="409.0" layoutY="267.0" prefHeight="168.0" prefWidth="385.0" text="Generate it">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button fx:id="GenerateButton" layoutX="14.0" layoutY="14.0" mnemonicParsing="false" prefHeight="31.0" prefWidth="353.0" text="Generate virtual amiibo" />
<Button fx:id="GenerateOneButton" layoutX="14.0" layoutY="95.0" mnemonicParsing="false" prefHeight="31.0" prefWidth="353.0" text="Generate virtual amiibo" />
<CheckBox fx:id="GenerateOneFtpCheck" layoutX="14.0" layoutY="24.0" mnemonicParsing="false" text="Save to FTP" />
<Label layoutX="14.0" layoutY="56.0" text="ftp://" />
<TextField fx:id="GenerateOneFtpAddress" layoutX="47.0" layoutY="52.0" promptText="Address" />
<Label layoutX="210.0" layoutY="56.0" text=":" />
<TextField fx:id="GenerateOneFtpPort" layoutX="215.0" layoutY="51.0" prefHeight="28.0" prefWidth="80.0" promptText="Port" />
</children>
</AnchorPane>
</content>
Expand All @@ -117,25 +123,37 @@
<content>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<TitledPane animated="false" layoutX="14.0" layoutY="14.0" prefHeight="189.0" prefWidth="362.0" text="Generate all">
<TitledPane animated="false" layoutX="14.0" layoutY="14.0" prefHeight="255.0" prefWidth="365.0" text="Generate all">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="91.0" prefWidth="770.0">
<children>
<Button fx:id="GenerateAllButton" layoutX="13.0" layoutY="115.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="333.0" text="Generate virtual amiibos" />
<Button fx:id="GenerateAllButton" layoutX="12.0" layoutY="179.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="333.0" text="Generate virtual amiibos" />
<CheckBox fx:id="GenerateAllUseRandomUuidCheck" layoutX="13.0" layoutY="14.0" mnemonicParsing="false" text="Enable UUID randomization" />
<CheckBox fx:id="GenerateAllImageSaveCheck" layoutX="13.0" layoutY="61.0" mnemonicParsing="false" text="Save images" />
<CheckBox fx:id="GenerateAllImageSaveCheck" layoutX="13.0" layoutY="52.0" mnemonicParsing="false" text="Save images" />
<Label layoutX="209.0" layoutY="141.0" text=":" />
<TextField fx:id="GenerateAllFtpPort" layoutX="214.0" layoutY="136.0" prefHeight="27.0" prefWidth="80.0" promptText="Port" />
<TextField fx:id="GenerateAllFtpAddress" layoutX="47.0" layoutY="136.0" prefHeight="27.0" prefWidth="160.0" promptText="Address" />
<Label layoutX="14.0" layoutY="141.0" text="ftp://" />
<CheckBox fx:id="GenerateAllFtpCheck" layoutX="13.0" layoutY="114.0" mnemonicParsing="false" text="Save to FTP" />
<Separator layoutX="14.0" layoutY="93.0" prefHeight="0.0" prefWidth="330.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" layoutX="387.0" layoutY="14.0" prefHeight="268.0" prefWidth="401.0" text="Generate by series">
<TitledPane animated="false" layoutX="387.0" layoutY="14.0" prefHeight="310.0" prefWidth="404.0" text="Generate by series">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="232.0" prefWidth="397.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="284.0" prefWidth="402.0">
<children>
<SearchableComboBox fx:id="GenerateSeriesAmiiboSeriesBox" layoutX="14.0" layoutY="14.0" prefHeight="31.0" prefWidth="369.0" />
<Button fx:id="GenerateSeriesButton" layoutX="14.0" layoutY="195.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="368.0" text="Generate virtual amiibos" />
<CheckBox fx:id="GenerateSeriesUseRandomUuidCheck" layoutX="14.0" layoutY="81.0" mnemonicParsing="false" text="Enable UUID randomization" />
<CheckBox fx:id="GenerateSeriesImageSaveCheck" layoutX="14.0" layoutY="134.0" mnemonicParsing="false" text="Save images" />
<Button fx:id="GenerateSeriesButton" layoutX="13.0" layoutY="234.0" mnemonicParsing="false" prefHeight="32.0" prefWidth="368.0" text="Generate virtual amiibos" />
<CheckBox fx:id="GenerateSeriesUseRandomUuidCheck" layoutX="14.0" layoutY="67.0" mnemonicParsing="false" text="Enable UUID randomization" />
<CheckBox fx:id="GenerateSeriesImageSaveCheck" layoutX="14.0" layoutY="107.0" mnemonicParsing="false" text="Save images" />
<CheckBox fx:id="GenerateSeriesFtpCheck" layoutX="14.0" layoutY="169.0" mnemonicParsing="false" text="Save to FTP" />
<Label layoutX="14.0" layoutY="197.0" text="ftp://" />
<TextField fx:id="GenerateSeriesFtpAddress" layoutX="47.0" layoutY="192.0" prefHeight="27.0" prefWidth="161.0" promptText="Address" />
<Label layoutX="211.0" layoutY="196.0" text=":" />
<TextField fx:id="GenerateSeriesFtpPort" layoutX="216.0" layoutY="192.0" prefHeight="27.0" prefWidth="80.0" promptText="Port" />
<Separator layoutX="12.0" layoutY="147.0" prefHeight="3.0" prefWidth="371.0" />
</children>
</AnchorPane>
</content>
Expand Down
2 changes: 1 addition & 1 deletion emuiigen/src/AmiiboAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AmiiboAPI {
}

fun readApi() : Map<String, List<AmiiboAPIEntry>>? {
val cur_path = Path.of(URLDecoder.decode(this.javaClass.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8")).parent;
val cur_path = Path.of(URLDecoder.decode(this::class.java.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8")).parent;
val local_api_json_path = Paths.get(cur_path.toAbsolutePath().toString(), "api.json").toString();

try {
Expand Down
51 changes: 51 additions & 0 deletions emuiigen/src/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.xortroll.emuiibo.emuiigen

import org.apache.commons.io.FilenameUtils
import org.apache.commons.io.IOUtils
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPReply
import java.net.URL
import java.nio.charset.StandardCharsets
import java.nio.channels.Channels
Expand Down Expand Up @@ -40,6 +43,16 @@ class Utils {
return Normalizer.normalize(str, Normalizer.Form.NFD).replace("[^\\p{ASCII}]".toRegex(), "");
}

fun ensureValidFileDirectoryName(str: String) : String {
// Ensure valid ASCII (for Switch filesystem)
val str_no_trailing_dots = str.trimEnd('.');

// Ensure no trailing dots (for NTFS)
val str_no_accents = unaccentString(str_no_trailing_dots);

return str_no_accents;
}

fun truncateString(str: String, len: Int) : String {
if(str.length > len) {
return str.substring(0, len);
Expand All @@ -48,5 +61,43 @@ class Utils {
return str;
}
}

fun ensureFtpDirectory(client: FTPClient, dir: String) : Boolean {
var dir_exists = true;

val items = dir.split("/");
for(item in items) {
if(!item.isEmpty()) {
if(dir_exists) {
dir_exists = client.changeWorkingDirectory(item);
}
if(!dir_exists) {
if(!client.makeDirectory(item)) {
return false;
}
if(!client.changeWorkingDirectory(item)) {
return false;
}
}
}
}

return true;
}

val RemovableAmiiboNameCharacters = charArrayOf(' ', '-', '.', '\'');

fun produceAmiiboName(base_name: String) : String {
// To retain as much of the name as possible when clamping to the limit, remove spaces and other less important ones
var name = base_name;
for(ch in RemovableAmiiboNameCharacters) {
name = name.replace(ch.toString(), "");
}

// Now apply the limit
name = truncateString(name, Amiibo.NameMaxLength);

return name;
}
}
}
Loading

0 comments on commit 3b0d98e

Please sign in to comment.