Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ruanformigoni/gameimage
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ruanformigoni/gameimage
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: backend.common
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 23 files changed
  • 1 contributor

Commits on Apr 12, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    stavros-k Stavros Kois
    Copy the full SHA
    7f9ca9f View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    stavros-k Stavros Kois
    Copy the full SHA
    593e00a View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    stavros-k Stavros Kois
    Copy the full SHA
    f750d00 View commit details
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/
gui/target
gui/shared/target
gui/launcher/target
gui/wizard/target
src/build
2 changes: 1 addition & 1 deletion deploy/Dockerfile.alpine.wizard
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ RUN cd gui/wizard && cargo build --release --target=x86_64-unknown-linux-musl

# Patch
RUN chmod +x ./deploy/makeself-wizard.sh
RUN ./deploy/makeself-wizard.sh "/gameimage/gui/wizard/target/x86_64-unknown-linux-musl/release/wizard"
RUN ./deploy/makeself-wizard.sh "/gameimage/gui/target/x86_64-unknown-linux-musl/release/wizard"

# Make dist
RUN mkdir /dist
4 changes: 2 additions & 2 deletions deploy/Dockerfile.arch.launcher
Original file line number Diff line number Diff line change
@@ -23,6 +23,6 @@ WORKDIR gameimage
# Compile
RUN cd gui/launcher && cargo build --release

# Make dist
# Move to dist
RUN mkdir /dist
RUN cp ./gui/launcher/target/release/launcher /dist/launcher
RUN cp ./gui/target/release/launcher /dist/launcher
108 changes: 17 additions & 91 deletions gui/wizard/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::
{
io::Read,
sync::{Arc,Mutex,mpsc,OnceLock},
sync::{Mutex,OnceLock},
env,
path,
};

use fltk::app;

use anyhow::anyhow as ah;

use crate::frame;
@@ -127,6 +124,22 @@ macro_rules! log
}
// }}}

// macro_rules log_return_err! {{{
#[macro_export]
macro_rules! log_return_err
{
($($arg:tt)*) => { { log!($($arg)*); return Err(ah!($($arg)*)); } }
}
// }}}

// macro_rules log_return_void! {{{
#[macro_export]
macro_rules! log_return_void
{
($($arg:tt)*) => { { log!($($arg)*); return; } }
}
// }}}

// pub fn wizard_by_platform() {{{
pub fn wizard_by_platform() -> anyhow::Result<Msg>
{
@@ -150,91 +163,4 @@ pub fn dir_build() -> anyhow::Result<()>
Ok(env::set_current_dir(path::PathBuf::from(env::var("GIMG_DIR")?))?)
} // fn: dir_build }}}

// pub fn gameimage_async() {{{
pub fn gameimage_async(args : Vec<&str>) -> anyhow::Result<mpsc::Receiver<i32>>
{
dir_build()?;

let path_binary_gameimage = path::PathBuf::from(env::var("GIMG_BACKEND")?);

let handle = std::process::Command::new(path_binary_gameimage)
.env_remove("LD_PRELOAD")
.env("FIM_FIFO", "0")
.stderr(std::process::Stdio::inherit())
.stdout(std::process::Stdio::piped())
.args(args)
.spawn()?;


// Create arc reader for stdout
let arc_handle = Arc::new(Mutex::new(handle));

// Clone process handle
let clone_arc_handle = arc_handle.clone();

// Create t/r
let (tx, rx) = mpsc::channel();
std::thread::spawn(move ||
{
// Acquire stdout
let mut lock =
if let Ok(lock) = clone_arc_handle.lock() && lock.stdout.is_some()
{
lock
}
else
{
impl_log("Could not acquire lock");
let _ = tx.send(1);
return;
}; // else

// Create buf
let mut buf = vec![0; 4096];

// Use buf to write buf to stdout & stderr
loop
{
std::thread::sleep(std::time::Duration::from_millis(50));

let bytes_read = match lock.stdout.as_mut().unwrap().read(&mut buf)
{
Ok(bytes_read) => bytes_read,
Err(_) => break,
};

if bytes_read == 0 { break; }
let output = String::from_utf8_lossy(&buf[..bytes_read]);
impl_log(&output);
}

if let Ok(status) = lock.wait() && let Some(code) = status.code()
{
let _ = tx.send(code);
}
else
{
let _ = tx.send(1);
} // else

app::awake();
});

Ok(rx)
} // fn: gameimage_async }}}

// pub fn gameimage_sync() {{{
pub fn gameimage_sync(args : Vec<&str>) -> i32
{
if let Ok(rx) = gameimage_async(args)
&& let Ok(code) = rx.recv()
{
return code;
} // if

impl_log("Could not retrieve exit code from backend");

1
} // fn: gameimage_sync }}}

// vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :
12 changes: 7 additions & 5 deletions gui/wizard/src/frame/creator.rs
Original file line number Diff line number Diff line change
@@ -17,14 +17,15 @@ use fltk::{

use shared::fltk::WidgetExtExtra;
use shared::fltk::SenderExt;
use shared::svg;
use shared::std::PathBufExt;

use crate::dimm;
use crate::frame;
use crate::common;
use shared::std::PathBufExt;
use crate::log;
use crate::db;
use shared::svg;
use crate::gameimage;

// fn create_entry() {{{
fn create_entry(project : db::project::Entry
@@ -276,10 +277,11 @@ pub fn creator(tx: Sender<common::Msg>, title: &str)
log!("File: {}", path_file_dwarfs.string());

// Wait for message & check return value
if common::gameimage_sync(vec!["package", &path_file_dwarfs.string()]) != 0
match gameimage::package::package(&path_file_dwarfs)
{
log!("Could not include {} into the image", path_file_dwarfs.string());
} // if
Ok(()) => log!("Packaged {}", path_file_dwarfs.string()),
Err(e) => log!("Could not include {} into the image: {}", path_file_dwarfs.string(), e),
} // match
} // for

// Refresh
12 changes: 6 additions & 6 deletions gui/wizard/src/frame/desktop.rs
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ use fltk::app::Sender;
use shared::fltk::SenderExt;

use crate::common;
use shared::std::PathBufExt;
use crate::log;
use crate::log_return_void;
use crate::gameimage;

// pub fn desktop() {{{
pub fn desktop(tx: Sender<common::Msg>, title: &str)
@@ -46,12 +47,11 @@ pub fn desktop(tx: Sender<common::Msg>, title: &str)
{
// Set as desktop entry icon for image
// Wait for message & check return value
if common::gameimage_sync(vec!["desktop", &path_file_icon.string()]) != 0
match gameimage::desktop::desktop(&path_file_icon)
{
log!("Failed to execute desktop command on backend");
clone_tx.send_awake(common::Msg::WindActivate);
return;
} // if
Ok(()) => log!("Finished desktop configuration"),
Err(e) => { clone_tx.send_awake(common::Msg::WindActivate); log_return_void!("{}", e); }
} // match

clone_tx.send_awake(common::Msg::DrawName);
fltk::app::awake();
33 changes: 6 additions & 27 deletions gui/wizard/src/frame/fetch.rs
Original file line number Diff line number Diff line change
@@ -239,33 +239,12 @@ pub fn fetch(tx: Sender<common::Msg>, title: &str)
let mut clone_output_status = clone_output_status.clone();
std::thread::spawn(move ||
{
// Get platform
let str_platform = match env::var("GIMG_PLATFORM")
{
Ok(var) => var.to_lowercase(),
Err(e) =>
{
clone_tx.send(common::Msg::WindActivate);
log!("Could not read variable GIMG_PLATFORM: {}", e);
clone_output_status.set_value("Could not read variable GIMG_PLATFORM");
return;
},
};

let arg_only_file = format!("--only-file={}", clone_data.file_dest.string());
let args = vec![
"fetch"
, "--platform"
, &str_platform
, &arg_only_file
];

log!("Args to gameimage: {:?}", args);

if common::gameimage_sync(args) != 0
let path_file_dst = clone_data.file_dest.clone();
match gameimage::fetch::fetch(Some(path_file_dst.clone()))
{
log!("Failed to fetch file list");
} // if
Ok(_) => log!("Successfully fetched file {}", path_file_dst.string()),
Err(e) => log!("Failed to fetch file '{}' with error '{}'", path_file_dst.string(), e),
}; // match

match clone_state_backend.lock()
{
@@ -274,7 +253,7 @@ pub fn fetch(tx: Sender<common::Msg>, title: &str)
};

clone_tx.send(common::Msg::WindActivate);
clone_output_status.set_value("Download finished");
clone_output_status.set_value("Operation finished");
});
};

16 changes: 8 additions & 8 deletions gui/wizard/src/frame/icon.rs
Original file line number Diff line number Diff line change
@@ -22,12 +22,14 @@ use anyhow::anyhow as ah;

use shared::fltk::SenderExt;
use shared::scaling;
use shared::std::PathBufExt;

use crate::dimm;
use crate::frame;
use crate::common;
use shared::std::PathBufExt;
use crate::log;
use crate::log_return_void;
use crate::gameimage;

// resize_draw_image() {{{
fn resize_draw_image(mut frame : Frame, path_file_icon : PathBuf) -> anyhow::Result<()>
@@ -449,8 +451,7 @@ pub fn project(tx: Sender<common::Msg>
{
output_status.set_value("No icon selected");
clone_tx.send_awake(msg_curr);
log!("No Icon selected");
return;
log_return_void!("No Icon selected");
};

// Set selected icon as icon
@@ -460,12 +461,11 @@ pub fn project(tx: Sender<common::Msg>
// Try to install icon
log!("Installing icon...");

if common::gameimage_sync(vec!["install", "icon", &path_file_icon.string()]) != 0
match gameimage::install::icon(&path_file_icon)
{
log!("Could not install icon, use .jpg or .png");
clone_tx.send_awake(msg_curr);
return;
} // if
Ok(_) => log!("Successfully installed icon"),
Err(e) => { clone_tx.send_awake(msg_curr); log_return_void!("Could not install icon with error: {}", e); },
} // match

clone_tx.send_awake(msg_next);
});
18 changes: 18 additions & 0 deletions gui/wizard/src/gameimage/desktop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use shared::std::PathBufExt;

use anyhow::anyhow as ah;

use crate::gameimage::gameimage;

// pub fn desktop() {{{
pub fn desktop(path : &std::path::PathBuf) -> anyhow::Result<()>
{
// Wait for message & check return value
match gameimage::gameimage_sync(vec!["desktop", &path.string()])
{
0 => Ok(()),
ret => Err(ah!("Could not include {} into the image: {}", path.string(), ret)),
} // match
} // fn: desktop }}}

// vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :
30 changes: 30 additions & 0 deletions gui/wizard/src/gameimage/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::anyhow as ah;

use shared::std::PathBufExt;

use crate::log;
use crate::common;
use crate::lib;
@@ -93,6 +95,34 @@ pub fn set_url_dwarfs(str_url : &str) -> anyhow::Result<i32>
Ok(set_url("--url-dwarfs", str_url)?)
} // set_url_dwarfs() }}}

// fetch() {{{
pub fn fetch(opt_path_file_dst : Option<std::path::PathBuf>) -> anyhow::Result<i32>
{
let str_platform = gameimage::gameimage::platform()?.to_lowercase();

let mut args = vec![
"fetch"
, "--platform"
, &str_platform
];

let str_path_file_dst;
if let Some(path_file_dst) = opt_path_file_dst
{
str_path_file_dst = path_file_dst.string();
args.push("--only-file");
args.push(&str_path_file_dst);
} // if

match gameimage::gameimage::gameimage_sync(args)
{
0 => log!("Fetch on backend finished successfully"),
rc => { log_return!("Failed to execute fetch on backend with {}", rc); },
} // match

Ok(0)
} // fetch() }}}

// validate() {{{
pub fn validate() -> anyhow::Result<i32>
{
16 changes: 16 additions & 0 deletions gui/wizard/src/gameimage/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::anyhow as ah;

use crate::gameimage::gameimage;

// pub fn init() {{{
pub fn init(name : String, platform : String, path_file_image : String) -> anyhow::Result<()>
{
// Wait for message & check return value
match gameimage::gameimage_sync(vec!["init", "--dir", &name, "--platform", &platform, "--image", &path_file_image ])
{
0 => Ok(()),
ret => Err(ah!("Could not init gameimage project: {}", ret)),
} // match
} // fn: init }}}

// vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :
Loading