Skip to content

Commit

Permalink
Allow zeus projects to be created in empty directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Layl Conway committed Jun 10, 2015
1 parent 09b23e4 commit 6d97238
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Error for ZeusProjectError {
impl Display for ZeusProjectError {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let message: String = match *self {
ZeusProjectError::AlreadyExists => String::from("Destination path already exists."),
ZeusProjectError::AlreadyExists => String::from("Destination path already exists and is not empty."),
ZeusProjectError::NotAZeusProject => String::from("Destination path is not a Zeus project."),
ZeusProjectError::InvalidPath => String::from("Destination path is not valid."),
ZeusProjectError::CorruptedFile(ref file) => format!("The file {} has been corrupted and could not be read.", file)
Expand Down Expand Up @@ -92,17 +92,25 @@ impl ZeusProject {
pub fn create(target_dir: PathBuf) -> Result<ZeusProject, ZeusProjectError> {
// Sanity check the path
if target_dir.to_str().unwrap().is_empty() { return Err(ZeusProjectError::InvalidPath) }
if target_dir.exists() { return Err(ZeusProjectError::AlreadyExists); }

// Check if the directory already exists
if target_dir.exists() {
// It does, check if it's empty
if fs::read_dir(target_dir.clone()).unwrap().count() != 0 {
// It isn't empty, we can't create a project here
return Err(ZeusProjectError::AlreadyExists);
}
} else {
// It doesn't create it
fs::create_dir_all(target_dir.clone()).unwrap();
}

// Create the actual project
let project = ZeusProject {
directory: target_dir,
game_name: String::from("My Game")
};

// Create the directory for this project
fs::create_dir_all(project.directory.clone()).unwrap();

// Generate the sample project file
// TODO: Use some templating library
let proj_toml = str::replace(PROJ_TOML, "{{game_name}}", "My Game");
Expand Down
8 changes: 4 additions & 4 deletions zeusgui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() {
opengl,
WindowSettings::new(
"Athena".to_string(),
Size { width: 500, height: 200 }
Size { width: 600, height: 200 }
)
.exit_on_esc(true)
.samples(4)
Expand All @@ -65,13 +65,13 @@ fn main() {
// Draw a path textbox
TextBox::new(&mut path)
.xy(-50.0, 50.0)
.dimensions(300.0, 30.0)
.font_size(14)
.dimensions(400.0, 30.0)
.font_size(11)
.react(|_string: &mut String|{})
.set(0, ui);

Button::new()
.xy(150.0, 50.0)
.xy(200.0, 50.0)
.dimensions(100.0, 30.0)
.label("Browse")
.react(|| path = browse_pressed())
Expand Down

0 comments on commit 6d97238

Please sign in to comment.