Skip to content

Commit

Permalink
Add bindings for the new game dir detection
Browse files Browse the repository at this point in the history
  • Loading branch information
redstrate committed May 26, 2024
1 parent ff606a9 commit 07193fc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions src/existing_dirs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later

use std::ffi::c_char;
use std::mem;
use std::ptr::null_mut;
use physis::existing_dirs::{ExistingInstallType, find_existing_game_dirs, find_existing_user_dirs};
use crate::ffi_to_c_string;

/// An existing install location on disk
#[repr(C)]
pub struct physis_ExistingGameDirectory {
/// The application where this installation was from
pub install_type : ExistingInstallType,
/// The path to the "main folder" where "game" and "boot" sits
pub path: *const c_char
}

#[repr(C)]
pub struct physis_ExistingGameDirectories {
pub count: u32,
pub entries: *mut physis_ExistingGameDirectory
}

#[no_mangle]
pub extern "C" fn physis_find_existing_game_dirs() -> physis_ExistingGameDirectories {
let dirs = find_existing_user_dirs();

let mut c_dirs = Vec::new();
for dir in dirs {
c_dirs.push(physis_ExistingGameDirectory {
path: ffi_to_c_string(&dir.path),
install_type: dir.install_type
});
}

let new_dirs = physis_ExistingGameDirectories {
count: c_dirs.len() as u32,
entries: c_dirs.as_mut_ptr()
};

mem::forget(c_dirs);

new_dirs
}

/// An existing user directory
#[repr(C)]
pub struct physis_ExistingUserDirectory {
/// The application where this directory was from
pub install_type : ExistingInstallType,
/// The path to the user folder
pub path: *const c_char
}

#[repr(C)]
pub struct physis_ExistingUserDirectories {
pub count: u32,
pub entries: *mut physis_ExistingUserDirectory
}

#[no_mangle]
pub extern "C" fn physis_find_existing_user_dirs() -> physis_ExistingUserDirectories {
let dirs = find_existing_user_dirs();

let mut c_dirs = Vec::new();
for dir in dirs {
c_dirs.push(physis_ExistingUserDirectory {
path: ffi_to_c_string(&dir.path),
install_type: dir.install_type
});
}

let new_dirs = physis_ExistingUserDirectories {
count: c_dirs.len() as u32,
entries: c_dirs.as_mut_ptr()
};

mem::forget(c_dirs);

new_dirs
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ mod index;
mod logging;

mod schd;
mod existing_dirs;

0 comments on commit 07193fc

Please sign in to comment.