arcadenea / iso2opl

Fork of iso2opl, taken from the Open Ps2 Loader repo. It has a better makefile in order to build succesfully
42 stars 10 forks source link

less/more verbose? #11

Open retrosapien opened 2 days ago

retrosapien commented 2 days ago

this line in iso2opl.c is all that needs to be changed. (I mistakenly said there is two, below. The first is in a comment block. I initially didn't have colours on in my editor and missed that.)

295                printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));

change the /n to a /r and add a fflush(sdtout), so;

295                printf("Writing %d sectors to %s - LBA: %d\r", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));
NEW              fflush(stdout);

and a new line added after the file is closed;

313        fclose(fh_part);
NEW printf("\n");

TL;DR

Can you add an option to make this less/more verbose?

I'm specifically interested in this line; Writing 256 sectors to /home/user/ul.AB6C56EC.SLUS_218.65.01 - LBA: 4162559 Writing 256 sectors to /home/user/ul.AB6C56EC.SLUS_218.65.01 - LBA: 4162815 ...

Can this line be updated inplace until it is finished writing so that it never takes more than one line in the terminal? Maybe use a pause and reset combo or something?

Something like this after the printf(...

System("clear");
system("cls");
printf("\e[1;1H\e[2J");

Above found here; https://www.geeksforgeeks.org/clear-console-c-language/ The printf(regex... is supposed to be the fastest.

I found these two lines in iso2opl.c that i think are relevant;

249             printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));

295                printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));

Maybe add that regex after those lines?

249             printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));
                                printf("\e[1;1H\e[2J");
295                printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));
                       printf("\e[1;1H\e[2J");

That change made an error during compile;

iso2opl.c: In function ‘write_parts’:
iso2opl.c:297:10: warning: non-ISO-standard escape sequence, '\e'
   printf("\e[1;1H\e[2J");
          ^~~~~~~~~~~~~~
iso2opl.c:297:10: warning: non-ISO-standard escape sequence, '\e'
cc isofs.o iso2opl.o -o iso2opl

Tried with;

system("cls");

returned;

sh: 1: cls: not found

Trying with;

system("clear");

Last one works, but need a sleep command or it clears too fast to read any thing.

Moved the system("clear"); before the printf( "Writing... line, and added a sleep(2);

Success!

Here is how i edited the file;

                                system("clear");
                printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));
                sleep(2);

The text is the same on both lines, just the indenting is different. Actually, the sleep command is not even needed. Just change to;

                                system("clear");
                printf("Writing %d sectors to %s - LBA: %d\n", WR_SIZE >> 11, part_path, (int)(iso_pos >> 11));

The only thing i don't like is that it clears the whole screen. I would prefer if it only cleared that line. But at least it works.

retrosapien commented 2 days ago

I tried to just redirect stdout to /dev/null, but it looks like all errors are printed on stdout, too! Should they not be printed to stderr?

Looks like the error messages just needs to be changed from;

printf("Error: ...
to fprintf(stderr, "Error:...

Can change all error messages with these; To see what will be changed;

$ sed -n "s/printf(\\"Error/fprintf(stderr, \\"Error/gp" iso2opl.c        
fprintf(stderr, "Error: failed to open ISO file: %s\n", isofile);
                fprintf(stderr, "Error: can't open SYSTEM.CNF from ISO file: %s\n", isofile);
                fprintf(stderr, "Error: failed to read SYSTEM.CNF from ISO file: %s\n", isofile);
                fprintf(stderr, "Error: failed to parse SYSTEM.CNF from ISO file: %s\n", isofile);
                fprintf(stderr, "Error: failed to locate elf path from ISO file: %s\n", isofile);
                fprintf(stderr, "Error: a game with the same ID is already installed on drive!\n");
                fprintf(stderr, "Error: can't read ul.cfg on drive!\n");
                fprintf(stderr, "Error: failed to allocate memory to read ISO!\n");
                fprintf(stderr, "Error: game part creation failed!\n");
                fprintf(stderr, "Error: failed to read datas from ISO file!\n");
                fprintf(stderr, "Error: failed to write datas to part file!\n");
                fprintf(stderr, "Error: can't open ul.cfg!\n");
                fprintf(stderr, "Error: write to ul.cfg failed!\n");

Then use this to edit the file;

$ sed -i "s/printf(\\"Error/fprintf(stderr, \\"Error/g" iso2opl.c 

Compiled and ran as expected! Can now redirect stdout to /dev/null without missing error messeges.

But i also noticed there is no error message for using a [GAME_NAME] greater than 32 characters. It just outputs the usage message.

Found this in iso2opl.c;

if ((argc < 5) || (strcmp(argv[4], "CD") && strcmp(argv[4], "DVD")) || (strlen(argv[3]) > 32)) {
        printUsage();
        exit(EXIT_FAILURE);

I think it is checking string length of argv 3 -> the GAME_NAME, but this should have a dedicated error message, since the usage message does not mention the 3-32 character requirement. If it did, i guess printing the usage message would be fine.