I've asked this earlier: Self app directory
To sum it up, you can't directly know which is the proper storage directory of a specific application in a Cargo project. You're able to do this:
- Get the path of the application executable
- Get the user documents directory
- Get the data directory
2 problems:
- Rust
std::fs
orstd::path
aren't aware about which is the application Id. The application Id will be determined at the project settings. Not sure, but one of the replies to my earlier topic above show it's possible to get the crate name. But the crate name isn't the proper project Id (which usually contain dot-delimited parts for most platforms). For example, it might becom.qux.foo-app
orQux/FooApp
. - The proper base directory isn't necessarily the user documents directory (this will vary based on target OS).
I'm familiar with Adobe AIR SDK (ActionScript). There they support app:
and app-storage:
URLs for referring to application files. In Windows, at least until Windows 11, the app storage directory looks like C:/Users/foo-user/AppData/Roaming/com.qux.app-id
. In Android, IIRC it's either /data/com.qux.app-id
for installation directory and /sdcard/Android/com.qux.app-id
for storage directory.
I want to develop a SDK for taking care of this, however, the solution I'm planning will create this file at the Cargo project:
-
src
flx_setup.rs
The logic is, main.rs
will invoke flx_setup::setup()
. flx_setup.rs
will be initialized with empty code and change everytime the application is compiled (to adapt the current project Id to the application directory variables), debugged and exported to desired platforms. However, I'd like to add flx_setup.rs
to .gitignore
, but if I do this, main.rs
will have an error saying flx_setup.rs
doesn't exist.
This is what flx_setup.rs
looks like:
// DO NOT MODIFY THIS FILE
use flxsdk::filesystem::{
// these variables are for internal use only
APPLICATION_DIRECTORY,
APPLICATION_STORAGE_DIRECTORY,
};
pub fn setup() {
}
main.rs
:
#[macro_use]
extern crate lazy_static;
mod flx_setup;
pub mod localization;
pub fn main() {
// do not modify this line
flx_setup::setup();
}
How can I somehow hide flx_setup
?