Skip to content

Commit

Permalink
new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Oct 5, 2022
1 parent 3ca8c32 commit 4e7d77c
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/dvm.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "discord version manager for linux"
homepage = "https://github.com/diced/dvm"
repository = "https://github.com/diced/dvm.git"
license = "MIT"
version = "1.1.8"
version = "1.1.9"
authors = ["diced <pranaco2@gmail.com>"]
edition = "2021"

Expand Down
31 changes: 22 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ chmod +x dvm
```
# Usage
```
dvm 1.1.8
dvm 1.1.9
USAGE:
dvm <SUBCOMMAND>
Expand All @@ -42,13 +42,14 @@ FLAGS:
-V, --version Prints version information
SUBCOMMANDS:
completions get shell completions
help Prints this message or the help of the given subcommand(s)
install install the latest <type> of discord
remove remove the installed <type> of discord
run run discord with specific options
show show all installed versions
update update to the latest <type> of discord
completions get shell completions
help Prints this message or the help of the given subcommand(s)
install install the latest <type> of discord
install-open-asar install openasar for <type> of discord
remove remove the installed <type> of discord
run run discord with specific options
show show all installed versions
update update to the latest <type> of discord
```

# Installing Discord
Expand All @@ -60,7 +61,19 @@ This will do the following:
1. Download the latest stable tarball from discord
2. Extract it into $HOME/.dvm
3. Create a bin file that executes the executable
4. Copy desktop and icons to respectful folders
4. Copy desktop and icons to their folders

## Install Open Asar
If you forget to add the flag `-o` when installing discord, you can install open asar by doing
```sh
dvm install-open-asar stable
```
...or do it when installing discord
```sh
dvm install stable -o
```



## Installing multiple versions at once
You can install multiple versions at once, they will be executed one after the other.
Expand Down
22 changes: 19 additions & 3 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{ env, fs, path::Path};

use crate::{error, info, r#type::Type, success, Res, util::install_version};

pub async fn install(release_type: Type, verbose: bool) -> Res<()> {
pub async fn install(release_type: Type, verbose: bool, open_asar: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
Expand All @@ -17,13 +17,29 @@ pub async fn install(release_type: Type, verbose: bool) -> Res<()> {
Type::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", user, pascal_pkg)).exists();
let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();

if exists {
error!("{} is already installed", release_type);
}

let (latest, _) = install_version(false, release_type.clone(), verbose, user).await?;
let (latest, _) = install_version(false, release_type.clone(), verbose, user.clone()).await?;

if open_asar {
let asar_file = format!("/home/{}/.dvm/{}/resources/app.asar", user, pascal_pkg);

fs::rename(&asar_file, format!("{}.bak", &asar_file))?;
info!("renamed app.asar to app.asar.bak (if discord doesn't work after this, rename it back)");

let res = reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
.await?
.bytes()
.await?;

fs::write(&asar_file, res)?;

info!("downloaded openasar, if discord is open, restart it");
}

success!("installed {}:{}", release_type, latest);
Ok(())
Expand Down
41 changes: 41 additions & 0 deletions src/cli/install_openasar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::{env, fs, path::Path};

use crate::{error, info, r#type::Type, success, Res};

pub async fn install_openasar(release_type: Type, verbose: bool) -> Res<()> {
// create user var & create .dvm dirs
let user = env::var("USER")?;
fs::create_dir_all(format!("/home/{}/.dvm/bin", user))?;
if verbose {
info!("created .dvm dir")
}

let pascal_pkg = match release_type {
Type::STABLE => "Discord",
Type::PTB => "DiscordPTB",
Type::CANARY => "DiscordCanary",
Type::DEVELOPMENT => "DiscordDevelopment",
};

let exists = Path::new(&format!("/home/{}/.dvm/{}", &user, &pascal_pkg)).exists();

if !exists {
error!("{} is not installed", release_type);
}

let asar_file = format!("/home/{}/.dvm/{}/resources/app.asar", user, pascal_pkg);

fs::rename(&asar_file, format!("{}.bak", &asar_file))?;
info!("renamed app.asar to app.asar.bak (if discord doesn't work after this, rename it back)");

let res = reqwest::get("https://github.com/GooseMod/OpenAsar/releases/download/nightly/app.asar")
.await?
.bytes()
.await?;

fs::write(&asar_file, res)?;

success!("installed openasar, if discord is open, restart it");

Ok(())
}
3 changes: 2 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod install;
mod install_openasar;
mod remove;
mod show;
mod update;
mod run;

pub use {install::install, remove::remove, show::show, update::update, run::run};
pub use {install::install, install_openasar::install_openasar, remove::remove, show::show, update::update, run::run};
4 changes: 3 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub const VERSION: &str = "1.1.8";
pub const VERSION: &str = "1.1.9";
pub const INSTALL_DESC: &str = "install the latest <type> of discord";
pub const INSTALL_ALIASES: &[&str] = &["i", "in", "get"];
pub const INSTALL_OPENASAR_DESC: &str = "install openasar for <type> of discord";
pub const INSTALL_OPENASAR_ALIASES: &[&str] = &["asar", "oa"];
pub const UPDATE_DESC: &str = "update to the latest <type> of discord";
pub const UPDATE_ALIASES: &[&str] = &["u", "up", "upgrade"];
pub const REMOVE_DESC: &str = "remove the installed <type> of discord";
Expand Down
41 changes: 39 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
compile_error!("can only be compiled on linux ;)");

use clap::{AppSettings, Clap};
use dvm::{Res, cli::{install, remove, show, update, run}, common::*, common::VERSION, completions, error, r#type::Type};
use dvm::{Res, cli::{install, install_openasar, remove, show, update, run}, common::*, common::VERSION, completions, error, r#type::Type};

#[derive(Clap, Debug)]
#[clap(version = VERSION, setting = AppSettings::ColoredHelp)]
Expand All @@ -16,6 +16,9 @@ enum Command {
#[clap(about = INSTALL_DESC, aliases = INSTALL_ALIASES)]
Install(InstallOption),

#[clap(about = INSTALL_OPENASAR_DESC, aliases = INSTALL_OPENASAR_ALIASES)]
InstallOpenAsar(InstallOpenAsarOption),

#[clap(about = UPDATE_DESC, aliases = UPDATE_ALIASES)]
Update(UpdateOption),

Expand All @@ -39,6 +42,18 @@ struct InstallOption {

#[clap(short, long)]
verbose: bool,

#[clap(short, long)]
open_asar: bool
}

#[derive(Clap, Debug)]
struct InstallOpenAsarOption {
#[clap(possible_values = POSSIBLE_VALUES)]
r#type: Vec<String>,

#[clap(short, long)]
verbose: bool
}

#[derive(Clap, Debug)]
Expand Down Expand Up @@ -98,22 +113,44 @@ fn str_to_type(s: String) -> Type {
}
}

fn check_type_len(types: &Vec<String>) -> Res<()> {
if types.len() == 0 {
error!("no types provided");
}

Ok(())
}

#[tokio::main]
async fn main() -> Res<()> {
let opts = Opts::parse();

Ok(match opts.command {
Command::Install(opt) => {
check_type_len(&opt.r#type)?;

for r#type in opt.r#type {
install(str_to_type(r#type), opt.verbose).await?
install(str_to_type(r#type), opt.verbose, opt.open_asar).await?
}
}
Command::InstallOpenAsar(opt) => {
check_type_len(&opt.r#type)?;

for r#type in opt.r#type {
install_openasar(str_to_type(r#type), opt.verbose).await?
}
}

Command::Update(opt) => {
check_type_len(&opt.r#type)?;

for r#type in opt.r#type {
update(str_to_type(r#type), opt.verbose).await?
}
}
Command::Remove(opt) => {
check_type_len(&opt.r#type)?;

for r#type in opt.r#type {
remove(str_to_type(r#type), opt.verbose).await?
}
Expand Down
13 changes: 11 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,19 @@ pub async fn install_version(update: bool, release_type: Type, verbose: bool, us
fs::write(
&bin_path,
format!(
"#!/bin/sh\n/home/{}/.dvm/{}/{} \"$@\"\n",
user, pascal_pkg, pascal_pkg
r#"#!/usr/bin/env bash
USER_FLAGS_FILE="$HOME/.dvm/{}-flags.conf"
if [[ -f $USER_FLAGS_FILE ]]; then
USER_FLAGS="$(cat $USER_FLAGS_FILE | sed 's/#.*//')"
fi
exec /home/{}/.dvm/{}/{} "$@" $USER_FLAGS
"#,
pkg_name, user, pascal_pkg, pascal_pkg
),
)?;

if verbose {
info!("created executable bin")
}
Expand Down

0 comments on commit 4e7d77c

Please # to comment.