Skip to content

Commit

Permalink
feat: install_dir macro for custom args
Browse files Browse the repository at this point in the history
Now you can use the `install_dir` macro in your profile's custom args to
specify the installation directory for the game. This will allow you
launch multi-file games with emulators that require a directory of
files ( e.g. RPCS3 ).
  • Loading branch information
JMBeresford committed Oct 21, 2024
1 parent 0650d22 commit b78e4df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ const formSchema = z.object({
(args) =>
args.length === 0 ||
args.includes("{file}") ||
args.includes('"{file}"'),
args.includes('"{file}"') ||
args.includes("{install_dir}") ||
args.includes('"{install_dir}"'),
{
message: "Custom arguments must include {file}",
message: "Custom arguments must include {file} or {install_dir}",
},
),
}) satisfies InferSchema<Omit<NewEmulatorProfile, "emulatorId">>;
Expand All @@ -78,8 +80,8 @@ export function EditProfileDialog(props: Props) {
useUpdateEmulatorProfiles();

const pending = creationStatus === "pending" || updateStatus === "pending";
const canSubmit =
form.formState.isDirty && form.formState.isValid && !pending;
const { isDirty } = form.formState;
const canSubmit = isDirty && !pending;

const handleSubmit = useCallback(
(values: FormSchema) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ export function ProfileList(props: Props) {

<TableBody>
{profiles.map((profile) => (
<TableRow key={profile.id}>
<TableRow
key={profile.id}
className="border-none even:bg-secondary/20"
>
<TableCell className="w-auto min-w-[100px]">
{profile.name}
</TableCell>
Expand Down
20 changes: 15 additions & 5 deletions plugins/retrom-plugin-launcher/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use tracing::{info, instrument};
use crate::{desktop::GameProcess, LauncherExt, Result};

#[command]
#[instrument(skip_all)]
#[instrument(skip_all, fields(
game_id = payload.game.as_ref().map(|game| game.id),
emulator_profile_id = payload.emulator_profile.as_ref().map(|profile| profile.id)))]
pub(crate) async fn play_game<R: Runtime>(
app: AppHandle<R>,
payload: PlayGamePayload,
Expand All @@ -26,8 +28,10 @@ pub(crate) async fn play_game<R: Runtime>(
};

let game_id = game.id;
let profile = payload.emulator_profile.unwrap();
let emulator = payload.emulator.unwrap();
let profile = payload
.emulator_profile
.expect("No emulator profile provided");
let emulator = payload.emulator.expect("No emulator provided");
let maybe_default_file = payload.file;

let default_file_path = maybe_default_file
Expand Down Expand Up @@ -90,6 +94,11 @@ pub(crate) async fn play_game<R: Runtime>(
None => return Err(crate::Error::FileNotFound(game_id)),
};

let install_dir = match install_dir.canonicalize()?.to_str() {
Some(path) => path.to_string(),
None => return Err(crate::Error::FileNotFound(game_id)),
};

let mut cmd = launcher.get_open_cmd(&emulator.executable_path);

let args = if !profile.custom_args.is_empty() {
Expand All @@ -105,12 +114,13 @@ pub(crate) async fn play_game<R: Runtime>(
true => arg[1..arg.len() - 1].to_string(),
})
.map(|arg| arg.replace("{file}", &file_path))
.map(|arg| arg.replace("{install_dir}", &install_dir))
.collect()
} else {
vec![file_path]
};

info!("Args: {:?}", args);
info!("Args Constructed: {:?}", args);

cmd.args(args);

Expand Down Expand Up @@ -152,7 +162,7 @@ pub(crate) async fn play_game<R: Runtime>(
}

#[command]
#[instrument(skip_all)]
#[instrument(skip_all, fields(game_id = payload.game.as_ref().map(|game| game.id)))]
pub(crate) async fn stop_game<R: Runtime>(
app: AppHandle<R>,
payload: StopGamePayload,
Expand Down

0 comments on commit b78e4df

Please sign in to comment.