Skip to content

Commit

Permalink
Merge pull request #522 from KrahJohlito/mc
Browse files Browse the repository at this point in the history
fix memory cards
  • Loading branch information
rickgaiser committed Aug 30, 2021
2 parents 640d8be + 9c3dc27 commit 69ba293
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lng/lang_Polish.lng
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Wersja 0.26. W większości przetłumaczone przez dragolice. Ponownie tłumaczyć "próbowali" Jolek & KaiQ. Podziękowania dla Haker120, misiozola i innych z Forum CDRinfo.pl ("https://forum.cdrinfo.pl/f30/") za pomoc i sugestie.
# For Open PS2 Loader v1.0.0 + betas - Official OPL Beta thread @https://www.psx-place.com/threads/open-ps2-loader-language-pack.20547/
Open PS2 Loader %s
Polski
Zapisz Zmiany
Wróć
Ustawienia Sieci
Expand Down
2 changes: 1 addition & 1 deletion src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ void guiMainLoop(void)
guiResetNotifications();
guiCheckNotifications(1, 1);

if (gOPLPart[0] != NULL)
if (gOPLPart[0] != '\0')
showPartPopup = 1;

while (!gTerminate) {
Expand Down
51 changes: 23 additions & 28 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "include/system.h"
#include <string.h>
#include <malloc.h>
#include <osd_config.h>
#include <rom0_info.h>

#include "include/hdd.h"

Expand All @@ -35,23 +35,21 @@ int getFileSize(int fd)
return size;
}

#define MAX_ENTRY 128

static int checkMC()
{
int mc0_is_ps2card, mc1_is_ps2card;
int mc0_has_folder, mc1_has_folder;

if (mcID == -1) {
mc0_is_ps2card = 0;
DIR *mc0_root_dir = opendir("mc0:");
DIR *mc0_root_dir = opendir("mc0:/");
if (mc0_root_dir != NULL) {
closedir(mc0_root_dir);
mc0_is_ps2card = 1;
}

mc1_is_ps2card = 0;
DIR *mc1_root_dir = opendir("mc1:");
DIR *mc1_root_dir = opendir("mc1:/");
if (mc1_root_dir != NULL) {
closedir(mc1_root_dir);
mc1_is_ps2card = 1;
Expand Down Expand Up @@ -94,23 +92,6 @@ static int checkMC()
return mcID;
}

static void writeMCIcon(void)
{
int fd;

fd = openFile("mc?:OPL/opl.icn", O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0) {
write(fd, &icon_icn, size_icon_icn);
close(fd);
}

fd = openFile("mc?:OPL/icon.sys", O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0) {
write(fd, &icon_sys, size_icon_sys);
close(fd);
}
}

void checkMCFolder(void)
{
char path[32];
Expand All @@ -126,15 +107,23 @@ void checkMCFolder(void)
snprintf(path, sizeof(path), "mc%d:OPL/opl.icn", mcID & 1);
fd = open(path, O_RDONLY, 0666);
if (fd < 0) {
writeMCIcon();
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0) {
write(fd, &icon_icn, size_icon_icn);
close(fd);
}
} else {
close(fd);
}

snprintf(path, sizeof(path), "mc%d:OPL/icon.sys", mcID & 1);
fd = open(path, O_RDONLY, 0666);
if (fd < 0) {
writeMCIcon();
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC);
if (fd >= 0) {
write(fd, &icon_sys, size_icon_sys);
close(fd);
}
} else {
close(fd);
}
Expand All @@ -157,10 +146,16 @@ static int checkFile(char *path, int mode)

// in create mode, we check that the directory exist, or create it
if (mode & O_CREAT) {
int res = mkdir(path, 0777);
// Non-standard POSIX check: the error value is supposed to be assigned to errno, not the return value
if (res >= 0 || res == -EEXIST) {
return 0;
char dirPath[256];
char *pos = strrchr(path, '/');
if (pos) {
memcpy(dirPath, path, (pos - path));
dirPath[(pos - path)] = '\0';
int res = mkdir(dirPath, 0777);
// Non-standard POSIX check: the error value is supposed to be assigned to errno, not the return value
if (res >= 0 || res == -EEXIST) {
return 0;
}
}
}
}
Expand Down

0 comments on commit 69ba293

Please sign in to comment.