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

Package Manager: Auto select emulators that has roms present #1228

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions src/packageManager/apply.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef PACMAN_APPLY_H__
#define PACMAN_APPLY_H__

#include "utils/file.h"
#include "utils/log.h"

#include "./fileActions.h"
#include "./globals.h"

void applyAllChanges(bool auto_update)
{
// installation
char cmd[STR_MAX * 2 + 100];

SDL_Surface *surfaceBackground = IMG_Load("/mnt/SDCARD/.tmp_update/res/waitingBG.png");
SDL_Surface *surfaceMessage;

for (int nT = 0; nT < tab_count; nT++) {
const char *data_path = layer_dirs[nT];

if (strlen(data_path) == 0 || !exists(data_path))
continue;

SDL_Rect rectMessage = {10, 420, 603, 48};

for (int nLayer = 0; nLayer < package_count[nT]; nLayer++) {
Package *package = &packages[nT][nLayer];

bool should_apply =
auto_update || (package->installed && !package->complete) ||
package->changed;
bool should_install = package->installed != package->changed ||
(package->installed &&
!package->complete && !package->changed);

if (!should_apply)
continue;

if (should_install) {
printf_debug("Installing %s...\n", package->name);
SDL_BlitSurface(surfaceBackground, NULL, screen, NULL);

surfaceMessage = TTF_RenderUTF8_Blended(
font35, package->name, color_white);
SDL_BlitSurface(surfaceMessage, NULL, screen, &rectMessage);
SDL_FreeSurface(surfaceMessage);

SDL_BlitSurface(screen, NULL, video, NULL);
SDL_Flip(video);

sprintf(cmd, "/mnt/SDCARD/.tmp_update/script/pacman_install.sh \"%s\" \"%s\"", data_path, package->name);
system(cmd);
sync();

callPackageInstaller(data_path, package->name, true);
}
else if (package->installed) {
printf_debug("Removing %s...\n", package->name);
callPackageInstaller(data_path, package->name, false);

// app removal
char pathAppUninstall[1000];
sprintf(pathAppUninstall, "%s/%s", data_path, package->name);
appUninstall(pathAppUninstall, strlen(pathAppUninstall));
}
}
}
}

#endif // PACMAN_APPLY_H__
59 changes: 59 additions & 0 deletions src/packageManager/changes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef PACMAN_CHANGES_H__
#define PACMAN_CHANGES_H__

#include "./globals.h"

int changesInstalls(void)
{
int total = 0;
for (int i = 0; i < tab_count; i++)
total += changes_installs[i];
return total;
}

int changesRemovals(void)
{
int total = 0;
for (int i = 0; i < tab_count; i++)
total += changes_removals[i];
return total;
}

int changesTotal(void) { return changesInstalls() + changesRemovals(); }

int totalInstalls(void)
{
int total = 0;
for (int i = 0; i < tab_count; i++)
total += package_installed_count[i];
return total;
}

/**
* @brief Sets the "changed" value for each item and updates counts for a layer
*
* @param mode 0: all off, 1: all on, 2: auto
* @param layer
*/
void setItemsInstallValue(int mode, int layer)
{
for (int i = 0; i < package_count[layer]; i++) {
Package *package = &packages[layer][i];
bool is_active = mode == 2 ? package->has_roms : mode;
bool new_value = is_active != package->installed;

if (package->changed != new_value) {
package->changed = new_value;

if (package->installed) {
changes_removals[layer] += new_value ? 1 : -1;
if (!package->complete)
changes_installs[layer] += new_value ? -1 : 1;
}
else
changes_installs[layer] += new_value ? 1 : -1;
}
}
}

#endif // PACMAN_CHANGES_H__