Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of the whole application #246

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP Part 8: Refactor
  • Loading branch information
Vysp3r committed Feb 1, 2025
commit 6fe61f5de81fc5eee3c256e4a433a15086ad0138
2 changes: 1 addition & 1 deletion src/models/launchers/bottles.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ProtonPlus.Models.Launchers {
public class Bottles : Launcher {
public Bottles (Launcher.InstallationTypes installation_type) {
string[] directories = null;;
string[] directories = null;

switch (installation_type) {
case Launcher.InstallationTypes.SYSTEM:
Expand Down
2 changes: 1 addition & 1 deletion src/models/launchers/hgl.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ProtonPlus.Models.Launchers {
public class HeroicGamesLauncher : Launcher {
public HeroicGamesLauncher (Launcher.InstallationTypes installation_type) {
string[] directories = null;;
string[] directories = null;

switch (installation_type) {
case Launcher.InstallationTypes.SYSTEM:
Expand Down
2 changes: 1 addition & 1 deletion src/models/launchers/lutris.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace ProtonPlus.Models.Launchers {
public class Lutris : Launcher {
public Lutris (Launcher.InstallationTypes installation_type) {
string[] directories = null;;
string[] directories = null;

switch (installation_type) {
case Launcher.InstallationTypes.SYSTEM:
Expand Down
9 changes: 3 additions & 6 deletions src/models/release.vala
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
namespace ProtonPlus.Models {
public abstract class Release : Object {
public Widgets.ReleaseRow row { get; set; }

public Runner runner { get; set; }
public string title { get; set; }
public string displayed_title { get; set; }
public string description { get; set; }
public string release_date { get; set; }
public string download_url { get; set; }
public string page_url { get; set; }

public bool installed { get; set; }
internal bool canceled { get; set; }

public bool canceled { get; set; }
public string progress { get; set; }
public signal void send_message (string message);
}
}
90 changes: 52 additions & 38 deletions src/models/releases/basic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ namespace ProtonPlus.Models.Releases {
public class Basic : Release {
public string install_location { get; set; }
public int64 download_size { get; set; }
public State state { get; set; }

public enum State {
NOT_INSTALLED,
INSTALLED,
BUSY_INSTALLING,
BUSY_REMOVING,
}

public Basic.github (Runners.Basic runner, string title, string description, string release_date, int64 download_size, string download_url, string page_url) {
this.description = description;
Expand All @@ -19,32 +27,46 @@ namespace ProtonPlus.Models.Releases {
internal void shared (Runners.Basic runner, string title, string release_date, string download_url, string page_url) {
this.runner = runner;
this.title = title;
this.displayed_title = title;
this.description = description;
this.release_date = release_date;
this.download_url = download_url;
this.page_url = page_url;

install_location = runner.group.launcher.directory + runner.group.directory + "/" + runner.get_directory_name (title);
}

var row = new Widgets.ReleaseRows.Basic ();
row.initialize (this);

this.row = row;

installed = FileUtils.test (install_location, FileTest.IS_DIR);
protected void refresh_state () {
state = FileUtils.test (install_location, FileTest.IS_DIR) ? State.INSTALLED : State.NOT_INSTALLED;
}

public virtual async bool install () {
public async bool install () {
state = State.BUSY_INSTALLING;

send_message (_("The installation of %s has begun.").printf (title));

var install_success = yield start_install ();

if (canceled)
send_message (_("The installation of %s was canceled.").printf (title));
else if (install_success)
send_message (_("The installation of %s is complete.").printf (title));
else
send_message (_("An unexpected error occurred while installing %s.").printf (title));

refresh_state ();

return true;
}

protected virtual async bool start_install () {
send_message (_("Downloading..."));

string path = runner.group.launcher.directory + runner.group.directory + "/" + title + ".tar.gz";

var download_valid = yield Utils.Web.Download (download_url, path, () => canceled, (is_percent, progress) => row.install_dialog.progress_text = is_percent? @"$progress%" : Utils.Filesystem.convert_bytes_to_string (progress));
var download_valid = yield Utils.Web.Download (download_url, path, () => canceled, (is_percent, progress) => this.progress = is_percent? @"$progress%" : Utils.Filesystem.convert_bytes_to_string (progress));

if (!download_valid) {
install_error ();
return false;
}

Expand All @@ -54,63 +76,55 @@ namespace ProtonPlus.Models.Releases {

string source_path = yield Utils.Filesystem.extract (directory, title, ".tar.gz", () => canceled);

if (source_path == "") {
install_error ();
if (source_path == "")
return false;
}

send_message (_("Renaming..."));

var runner = this.runner as Runners.Basic;

var renaming_valid = yield Utils.Filesystem.rename (source_path, directory + runner.get_directory_name (title));

if (!renaming_valid) {
install_error ();
if (!renaming_valid)
return false;
}

send_message (_("Running post installation script..."));
send_message (_("Running installation script..."));

runner.group.launcher.install (this);

send_message (_("The installation of %s is complete.").printf (title));

installed = true;

return true;
}

protected void install_error () {
if (canceled)
send_message (_("The installation of %s was canceled.").printf (title));
public async bool remove () {
state = State.BUSY_REMOVING;

send_message (_("The removal of %s has begun.").printf (title));

var remove_success = yield start_remove ();

if (remove_success)
send_message (_("The removal of %s is complete.").printf (title));
else
send_message (_("An unexpected error occurred while installing %s.").printf (title));
send_message (_("An unexpected error occurred while removing %s.").printf (title));

refresh_state ();

return true;
}

public virtual async bool remove () {
send_message (_("The removal of %s has begun.").printf (title));
protected virtual async bool start_remove () {
send_message (_("Deleting..."));

var deleted = yield Utils.Filesystem.delete_directory (install_location);

if (!deleted) {
remove_error ();
if (!deleted)
return false;
}

send_message (_("Running post removal script..."));
send_message (_("Running removal script..."));

runner.group.launcher.uninstall (this);

send_message (_("The removal of %s is complete.").printf (title));

installed = false;

return true;
}

protected void remove_error () {
send_message (_("An unexpected error occurred while removing %s.").printf (title));
}
}
}
33 changes: 14 additions & 19 deletions src/models/releases/github-action.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,44 @@ namespace ProtonPlus.Models.Releases {

shared (runner, title, release_date, download_url, page_url);

row.set_title (@"$title ($release_date)");
displayed_title = @"$title ($release_date)";
}

public override async bool install () {
send_message (_("The installation of %s has begun.").printf (title));

protected override async bool start_install () {
send_message (_("Downloading..."));

string path = runner.group.launcher.directory + runner.group.directory + "/" + title + ".zip";
string path = runner.group.launcher.directory + runner.group.directory + "/" + title + ".tar.gz";

var download_valid = yield Utils.Web.Download (download_url, path, () => canceled, (is_percent, progress) => row.install_dialog.progress_text = is_percent? @"$progress%" : Utils.Filesystem.convert_bytes_to_string (progress));
var download_valid = yield Utils.Web.Download (download_url, path, () => canceled, (is_percent, progress) => this.progress = is_percent? @"$progress%" : Utils.Filesystem.convert_bytes_to_string (progress));

if (!download_valid) {
install_error ();
if (!download_valid)
return false;
}

send_message (_("Extracting..."));

string directory = runner.group.launcher.directory + "/" + runner.group.directory + "/";

string source_path = yield Utils.Filesystem.extract (directory, title, ".zip", () => canceled);
string source_path = yield Utils.Filesystem.extract (directory, title, ".tar.gz", () => canceled);

if (source_path == "") {
install_error ();
if (source_path == "")
return false;
}

source_path = yield Utils.Filesystem.extract (directory, source_path.substring (0, source_path.length - 4).replace (directory, ""), ".tar", () => canceled);

// TODO Check if the second extraction was good

send_message (_("Renaming..."));

var runner = this.runner as Runners.Basic;

yield Utils.Filesystem.rename (source_path, directory + runner.get_directory_name (title));

send_message (_("Running post installation script..."));
var renaming_valid = yield Utils.Filesystem.rename (source_path, directory + runner.get_directory_name (title));

runner.group.launcher.install (this);
if (!renaming_valid)
return false;

send_message (_("The installation of %s is complete.").printf (title));
send_message (_("Running installation script..."));

installed = true;
runner.group.launcher.install (this);

return true;
}
Expand Down
Loading