Feat(CLI) Icon Check fix: #309 (#310)

* add icon check for windows.

* fix spelling

* add basic icon logic

* make error more prolific
This commit is contained in:
Tensor-Programming
2020-01-12 20:27:35 -05:00
committed by GitHub
parent af98ed349b
commit ee2d714b67
3 changed files with 29 additions and 7 deletions

View File

@@ -43,3 +43,16 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<PathBuf>> {
}
Ok(paths)
}
// Check to see if there are icons in the settings struct
pub fn check_icons(settings: &Settings) -> crate::Result<bool> {
// make a peekable iterator of the icon_files
let mut iter = settings.icon_files().peekable();
// if iter's first value is a None then there are no Icon files in the settings struct
if iter.peek().is_none() {
Ok(false)
} else {
Ok(true)
}
}

View File

@@ -12,7 +12,7 @@ extern crate tempfile;
mod bundle;
use crate::bundle::{bundle_project, BuildArtifact, PackageType, Settings};
use crate::bundle::{bundle_project, check_icons, BuildArtifact, PackageType, Settings};
use clap::{App, AppSettings, Arg, SubCommand};
use std::env;
use std::process;
@@ -141,8 +141,14 @@ fn run() -> crate::Result<()> {
.map_err(From::from)
.and_then(|d| Settings::new(d, m))
.and_then(|s| {
build_project_if_unbuilt(&s)?;
Ok(s)
if check_icons(&s)? {
build_project_if_unbuilt(&s)?;
Ok(s)
} else {
Err(crate::Error::from(
"Could not find Icon Paths. Please make sure they exist and are in your Cargo.toml's icon key.",
))
}
})
.and_then(bundle_project)?;
bundle::print_finished(&output_paths)?;

View File

@@ -3,10 +3,13 @@ extern crate winres;
#[cfg(windows)]
fn main() {
let mut res = winres::WindowsResource::new();
res.set_icon("icons/icon.ico");
res.compile().expect("Unable to find visual studio tools");
}
if std::path::Path::new("icons/icon.ico").exists() {
let mut res = winres::WindowsResource::new();
res.set_icon("icons/icon.ico");
res.compile().expect("Unable to find visual studio tools");
} else {
panic!("No Icon.ico found. Please add one or check the path");
}
#[cfg(not(windows))]
fn main() {}