Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Cover scenarios when looking for resources folder #54

Merged
merged 2 commits into from
Jul 17, 2020

Conversation

henryksloan
Copy link
Contributor

Fixes #51

  • Added a function change_to_resources_parent_dir that gets called near the top of main
  • Searches for the resources folder by all three methods laid out in Cover more scenarios when looking for resources folder #51
    • Checks for resources in the working directory
    • Checks for resources in the parent directory of the binary (e.g. target/debug/gv_client => target/debug/resources)
    • Checks if the working directory is a child of $CARGO_MANIFEST_DIR/../.., and checks for resources in there ¹
  • If any of these scenarios occurs, the working directory is changed appropriately, along with a println! message
  • The priority of these scenarios is equal to the above list ordering (i.e. working directory is tried first)
  • On failure, returns Err(Error::new(ErrorKind::NotFound, "Could not find resources folder"))
  • main calls the function with ...?, so the game now exits gracefully with an error message to stdio if resources are not found

¹ Please verify that this is intended behavior. I have tested that it works as described above, but there may be a solution preferable to assuming that $CARGO_MANIFEST_DIR is two subdirectories down from root.

I have tested each of the scenarios listed, as well as the expected failure case (no resources folder in any of the expected locations) on Windows. I recommend that reviewers test them as well, especially on Linux and perhaps on MacOS. That said, the code only depends on std::path::PathBuf, so it should work as described.

@vladbat00
Copy link
Member

Thank you, looks great! I'll test it on MacOS today in the evening and if it works correctly for every scenario, I'm happy to merge it

@vladbat00
Copy link
Member

Works like a charm!

Please verify that this is intended behavior. I have tested that it works as described above, but there may be a solution preferable to assuming that $CARGO_MANIFEST_DIR is two subdirectories down from root.

As far as I know, there's no way to get workspace root directory, so I guess your approach is fine. I can see only 1 minor downside of it: the code will need to be updated if the package directory moves (and changes nesting level), but that's really unlikely.

@vladbat00 vladbat00 merged commit 38e7657 into amethyst:master Jul 17, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover more scenarios when looking for resources folder
2 participants