Code Monkey home page Code Monkey logo

Comments (2)

marvinlehmann avatar marvinlehmann commented on June 14, 2024 1

You're able to specify the maFiles folder that contains the manifest and .maFile files. =)

    -m, --mafiles-path <MAFILES_PATH>
            Specify which folder your maFiles are in. This should be a path to a folder that
            contains manifest.json. Default: ~/.config/steamguard-cli/maFiles
            
            [env: STEAMGUARD_CLI_MAFILES=]

But I also think that it would be nice to automatically select the maFiles folder if one exists in the current working/app directory.

from steamguard-cli.

marvinlehmann avatar marvinlehmann commented on June 14, 2024

If I had to nitpick on #277: The maFiles next to the exe should be prioritized over config_dir & home_dir... but if neither of them exist.

fn get_mafiles_dir() -> String {
	let mut paths = vec![
		Path::new(&dirs::config_dir().unwrap()).join("steamguard-cli/maFiles"),
		Path::new(&dirs::home_dir().unwrap()).join("maFiles"),
	];
	if let Ok(current_exe) = std::env::current_exe() {
		paths.insert(0, current_exe.parent().unwrap().join("maFiles")); // insert at the index 0 for priority
	}

	for path in &paths {
		if path.join("manifest.json").is_file() {
			return path.to_str().unwrap().into();
		}
	}

	return paths[1].to_str().unwrap().into(); // index 1 so it doesn't default to adjacent dir for creation/setup
}

I'm not really familiar with Rust but this seems to do it for me - minimal changes. =)

EDIT: Ah, I didn't consider a failing if let Ok(current_exe) = std::env::current_exe() .... That would mess up the "positioning". I guess a few more lines are needed.

EDIT2: Maybe something like this?

fn get_mafiles_dir() -> String {
	let default_path = Path::new(&dirs::config_dir().unwrap()).join("steamguard-cli/maFiles");
	let mut paths = vec![
		default_path.clone(),
		Path::new(&dirs::home_dir().unwrap()).join("maFiles"),
	];
	if let Ok(current_exe) = std::env::current_exe() {
		paths.insert(0, current_exe.parent().unwrap().join("maFiles"));
	}

	for path in &paths {
		if path.join("manifest.json").is_file() {
			return path.to_str().unwrap().into();
		}
	}

	return default_path.to_str().unwrap().into();
}

from steamguard-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.