merged from work

This commit is contained in:
2023-05-06 13:23:42 +02:00
parent 11e3a02511
commit 4e8c500fb2
592 changed files with 5577 additions and 71276 deletions

45
app-stub/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,45 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'app-stub'",
"cargo": {
"args": [
"build",
"--bin=app-stub",
"--package=app-stub"
],
"filter": {
"name": "app-stub",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'app-stub'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=app-stub",
"--package=app-stub"
],
"filter": {
"name": "app-stub",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

168
app-stub/Cargo.lock generated Normal file
View File

@ -0,0 +1,168 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "app-stub"
version = "0.2.0"
dependencies = [
"itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"simplelog 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "either"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"either 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "simplelog"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.77 (registry+https://github.com/rust-lang/crates.io-index)",
"wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chrono 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "942f72db697d8767c22d46a598e01f2d3b475501ea43d0db4f16d90259182d0b"
"checksum either 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f"
"checksum itertools 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
"checksum libc 0.2.77 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
"checksum log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
"checksum num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b"
"checksum num-traits 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611"
"checksum semver 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190"
"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
"checksum simplelog 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2b2736f58087298a448859961d3f4a0850b832e72619d75adc69da7993c2cd3c"
"checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
"checksum time 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
"checksum wasi 0.10.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
"checksum winapi 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

13
app-stub/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "app-stub"
version = "0.2.0"
authors = ["Holger Börchers <holgerb83@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
semver = "0.10.0"
log = "0.4.11"
simplelog = "0.8.0"
itertools = "0.9.0"

120
app-stub/src/main.rs Normal file
View File

@ -0,0 +1,120 @@
#![windows_subsystem = "windows"]
use itertools::Itertools;
use log::{error, info};
use semver::Version;
use simplelog::*;
use std::collections::BTreeMap;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::fs::File;
use std::option::Option;
use std::path::{Path, PathBuf};
fn main() {
if env::var("APPSTUB_DEBUG").is_ok() {
CombinedLogger::init(vec![
TermLogger::new(LevelFilter::Error, Config::default(), TerminalMode::Mixed),
WriteLogger::new(
LevelFilter::Info,
Config::default(),
File::create("app-stub.log").unwrap(),
),
])
.unwrap();
}
info!("Search for folders");
let app_folders = get_all_app_folders();
if let Some(executed_version) = execute_application(&app_folders) {
delete_old_versions(&app_folders, &executed_version);
}
}
fn execute_application(app_folders: &BTreeMap<Version, PathBuf>) -> Option<&Version> {
if let Some(executable_name) = get_executable_name() {
info!("Executable name: {:?}", executable_name);
if let Some(programm_to_start) = app_folders.iter().next_back() {
let folder = programm_to_start.1;
let mut path: PathBuf = PathBuf::from(folder);
path.push(Path::new(&executable_name));
info!("Path to start: {:?}", path);
let arguments = env::args().skip(1).format(" ");
info!("Arguments: {:?}", arguments);
let process = std::process::Command::new(path.as_os_str())
.args(env::args().skip(1))
.current_dir(folder)
.spawn();
match process {
Ok(out) => info!("{:?}", out),
Err(error) => error!("{:?}", error),
}
return Some(programm_to_start.0);
}
}
return None;
}
fn delete_old_versions(app_folders: &BTreeMap<Version, PathBuf>, executed_version: &Version) {
for app_folder in app_folders {
if app_folder.0 != executed_version {
info!("Foler to remove: {:?}", app_folder.1);
let remove_dir_all = std::fs::remove_dir_all(&app_folder.1);
match remove_dir_all {
Ok(out) => info!("{:?}", out),
Err(error) => error!("{:?}", error),
}
}
}
}
fn get_semantic_version(path: PathBuf) -> Option<Version> {
let last_component = path.components().last();
let folder_name = last_component?.as_os_str().to_str();
if folder_name?.to_lowercase().starts_with("app-") {
let strip_folder_name = folder_name?.get(4..folder_name?.len());
let parsed_semver = Version::parse(strip_folder_name?);
if let Ok(parsed_semver) = parsed_semver {
return Some(parsed_semver);
}
}
return None;
}
fn get_executable_name() -> Option<OsString> {
if let Ok(current_exe) = env::current_exe() {
if let Some(file_name) = current_exe.file_name() {
return Some(file_name.to_os_string());
}
}
return None;
}
fn get_all_app_folders() -> BTreeMap<Version, PathBuf> {
let mut app_folders: BTreeMap<Version, PathBuf> = BTreeMap::new();
if let Ok(current_exe) = env::current_exe() {
info!("Current executable: {:?}", current_exe);
if let Some(parent_dir) = current_exe.parent() {
info!("Parent directory: {:?}", parent_dir);
if let Ok(entries) = fs::read_dir(parent_dir) {
for entry in entries {
if let Ok(entry) = entry {
if let Ok(file_type) = entry.file_type() {
if file_type.is_dir() {
let semantic = get_semantic_version(entry.path());
if let Some(semantic) = semantic {
info!("Found folder (Version {:?}): {:?}", semantic, entry);
app_folders.insert(semantic, entry.path());
}
}
}
}
}
}
}
}
info!("Totally found {:?} folders", app_folders.len());
return app_folders;
}