-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
1098 lines (869 loc) · 21 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <malloc.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <psp2/ctrl.h>
#include <psp2/touch.h>
#include <psp2/display.h>
#include <psp2/gxm.h>
#include <psp2/types.h>
#include <psp2/moduleinfo.h>
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/kernel/threadmgr.h>
#include <psp2/kernel/sysmem.h>
#include "draw.h"
PSP2_MODULE_INFO(0, 0, "psp2shell");
#define ROOT_PATH "cache0:/"
#define START_PATH ROOT_PATH
// Default Start Path
// Current Path
static char cwd[1024];
enum {
MODE_HOMEBREW = 0,
MODE_ISO = 1,
MODE_POPS = 2,
MODE_MAX = 3,
};
// Runlevel Definition
#define HOMEBREW_RUNLEVEL 0x141
#define ISO_RUNLEVEL 0x123
#define POPS_RUNLEVEL 0x144
// Current Runlevel
// 0x144 = Pops
// 0x141 = Homebrew
// 0x123 = ISO / CSO / PSN
int mode = MODE_HOMEBREW;
// Copy Move Origin
static char copysource[1024];
// Copy Flags
#define COPY_FOLDER_RECURSIVE 2
#define COPY_DELETE_ON_FINISH 1
#define COPY_KEEP_ON_FINISH 0
#define NOTHING_TO_COPY -1
// Copy Mode
// -1 Nothing
// 0 Copy
// 1 Move
int copymode = NOTHING_TO_COPY;
// Generic Definitions
#define CLEAR 1
#define KEEP 0
// GUI Definitions
#define FONT_SIZE 7
#define PADDING 3
#define FONT_COLOR 0xFFFFFF
#define FONT_SELECT_COLOR 0xFFD800
#define BACK_COLOR 0xBCAD94
#define CENTER_X(s) (240 - ((strlen(s) * FONT_SIZE) >> 1))
#define RIGHT_X(s) (480 - (strlen(s) * FONT_SIZE))
#define CENTER_Y 132
#define FILES_PER_PAGE 18
// Button Test Macro
#define PRESSED(b, a, m) (((b & m) == 0) && ((a & m) == m))
// File Information Structure
typedef struct File
{
// Next Item
struct File * next;
// Folder Flag
int isFolder;
// File Name
char name[256];
} File;
// Prototypes
void printoob(char * text, int x, int y, unsigned int color);
void updateList(int clearindex);
void paintList(int withclear);
void recursiveFree(File * node);
void start(void);
int delete(void);
int navigate(void);
void copy(int flag);
int paste(void);
File * findindex(int index);
int delete_folder_recursive(char * path);
int copy_file(char * a, char * b);
int copy_folder_recursive(char * a, char * b);
int isPathISO(const char * path);
int isPathCSO(const char * path);
int isGameISO(const char * path);
// Menu Position
int position = 0;
// Number of Files
int filecount = 0;
// File List
File * files = NULL;
// Entry Point
int main()
{
// Set Start Path
strcpy(cwd, START_PATH);
// Initialize Screen Output
init_video();
// Update List
updateList(CLEAR);
// Paint List
paintList(KEEP);
// Last Buttons
unsigned int lastbuttons = 0;
// Input Loop
while(1)
{
// Button Data
SceCtrlData data;
// Clear Memory
memset(&data, 0, sizeof(data));
// Read Button Data
sceCtrlSetSamplingMode(1);
sceCtrlPeekBufferPositive(0, &data, 1);
// Other Commands
if(filecount > 0)
{
// Start File
if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_START))
{
// Start File
//start();
break;
}
// Delete File
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_SELECT))
{
// Delete File
if(delete() == 0)
{
// Update List
updateList(KEEP);
// Paint List
paintList(CLEAR);
}
}
// Position Decrement
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_UP))
{
// Decrease Position
if(position > 0) position--;
// Rewind Pointer
else position = filecount - 1;
// Paint List
paintList(KEEP);
}
// Position Increment
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_DOWN))
{
// Increase Position
if(position < (filecount - 1)) position++;
// Rewind Pointer
else position = 0;
// Paint List
paintList(KEEP);
}
// Runlevel Change
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_LEFT))
{
if(--mode < 0) mode = MODE_MAX - 1;
// Paint List
paintList(CLEAR);
}
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_RIGHT))
{
if(++mode >= MODE_MAX) mode = 0;
// Paint List
paintList(CLEAR);
}
// Navigate to Folder
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_CROSS))
{
// Attempt to navigate to Target
if(navigate() == 0)
{
// Update List
updateList(CLEAR);
// Paint List
paintList(CLEAR);
}
}
// Copy
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_SQUARE))
{
// Copy File
copy(COPY_KEEP_ON_FINISH);
// Paint List
paintList(KEEP);
}
// Cut
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_TRIANGLE))
{
// Copy File
copy(COPY_DELETE_ON_FINISH);
// Paint List
paintList(KEEP);
}
// Paste
else if(PRESSED(lastbuttons, data.buttons, PSP2_CTRL_CIRCLE))
{
// Paste File
if(paste() == 0)
{
// Update List
updateList(KEEP);
// Paint List
paintList(CLEAR);
}
}
}
// Copy Buttons to Memory
lastbuttons = data.buttons;
// Delay Thread (~100FPS are enough)
sceKernelDelayThread(10000);
}
end_video();
sceKernelExitProcess(0); // Exits PSM bubble
// Exit Function
return 0;
}
// Print Out of Bounds Text
void printoob(char * text, int x, int y, unsigned int color)
{
// Convert screen coordinates from 480x272 to 960x544
font_draw_string((x*2*95)/100, y*2, color, text);
}
// Update File List
void updateList(int clearindex)
{
// Clear List
recursiveFree(files);
files = NULL;
filecount = 0;
// Open Working Directory
int directory = sceIoDopen(cwd);
// Opened Directory
if(directory >= 0)
{
/* Add fake ".." entry except on root */
if (strcmp(cwd, ROOT_PATH)) {
// New List
files = (File *)malloc(sizeof(File));
// Clear Memory
memset(files, 0, sizeof(File));
// Copy File Name
strcpy(files->name, "..");
// Set Folder Flag
files->isFolder = 1;
filecount++;
}
// File Info Read Result
int dreadresult = 1;
// Iterate Files
while(dreadresult > 0)
{
// File Info
SceIoDirent info;
// Clear Memory
memset(&info, 0, sizeof(info));
// Read File Data
dreadresult = sceIoDread(directory, &info);
// Read Success
if(dreadresult >= 0)
{
// Ingore null filename
if(info.d_name[0] == '\0') continue;
// Ignore "." in all Directories
if(strcmp(info.d_name, ".") == 0) continue;
// Ignore ".." in Root Directory
if(strcmp(cwd, ROOT_PATH) == 0 && strcmp(info.d_name, "..") == 0) continue;
// Allocate Memory
File * item = (File *)malloc(sizeof(File));
// Clear Memory
memset(item, 0, sizeof(File));
// Copy File Name
strcpy(item->name, info.d_name);
// Set Folder Flag
item->isFolder = PSP2_S_ISDIR(info.d_stat.st_mode);
// New List
if(files == NULL) files = item;
// Existing List
else
{
// Iterator Variable
File * list = files;
// Append to List
while(list->next != NULL) list = list->next;
// Link Item
list->next = item;
}
// Increase File Count
filecount++;
}
}
// Close Directory
sceIoDclose(directory);
}
// Attempt to keep Index
if(!clearindex)
{
// Fix Position
if(position >= filecount) position = filecount - 1;
}
// Reset Position
else position = 0;
}
char *getModeStr(int mode)
{
switch(mode)
{/*
case MODE_HOMEBREW:
return "Application";
case MODE_ISO:
return "Game Image";
case MODE_POPS:
return "Pops";*/
case MODE_HOMEBREW:
return "Mode0";
case MODE_ISO:
return "Mode1";
case MODE_POPS:
return "Mode2";
}
return NULL;
}
// Paint Picker List
void paintList(int withclear)
{
// Clear Screen
//if(withclear)
clear_screen();
// Paint Current Path
printoob(cwd, 10, 10, FONT_COLOR);
// Paint Current Runlevel
char * strrunlevel = getModeStr(mode);
printoob(strrunlevel, RIGHT_X(strrunlevel) - 10, 10, FONT_COLOR);
// Paint Controls
printoob("[ UP & DOWN ] File Selection", 10, 252, FONT_COLOR);
printoob("[ LEFT & RIGHT ] Mode Selection", 10, 262, FONT_COLOR);
printoob("[ START ] Exit", 330, 252, FONT_COLOR);
printoob("[ SELECT ] Delete", 330, 262, FONT_COLOR);
printoob("SQUARE Copy", 345, 120, FONT_COLOR);
printoob("TRIANGLE Cut", 345, 130, FONT_COLOR);
printoob("CIRCLE Paste", 345, 140, FONT_COLOR);
printoob("CROSS Navigate", 345, 150, FONT_COLOR);
// Copy Paste in Progress
if(copymode != NOTHING_TO_COPY)
{
// Get Cache Source Filename
char * filename = NULL; int i = 0; for(; i < strlen(copysource); i++) if(copysource[i] == '/') filename = copysource + i + 1;
// Paint to Screen
printoob(filename, 10, 242, FONT_SELECT_COLOR);
}
// File Iterator Variable
int i = 0;
// Print Counter
int printed = 0;
// Paint File List
File * file = files;
for(; file != NULL; file = file->next)
{
// Printed enough already
if(printed == FILES_PER_PAGE) break;
// Interesting File
if(position < FILES_PER_PAGE || i > (position - FILES_PER_PAGE))
{
// Default Font Color
unsigned int color = FONT_COLOR;
// Selected File Font Color
if(i == position) color = FONT_SELECT_COLOR;
// Print Node Type
printoob((file->isFolder) ? ("D") : ("F"), 10, 30 + (FONT_SIZE + PADDING) * printed, FONT_COLOR);
char buf[64];
strncpy(buf, file->name, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
int len = strlen(buf);
len = 40 - len;
while(len -- > 0)
{
strcat(buf, " ");
}
// Print Filename
printoob(buf, 20, 30 + (FONT_SIZE + PADDING) * printed, color);
// Increase Print Counter
printed++;
}
// Increase Counter
i++;
}
swap_buffers();
sceDisplayWaitVblankStart();
}
// Free Heap Memory
void recursiveFree(File * node)
{
// End of List
if(node == NULL) return;
// Nest Further
recursiveFree(node->next);
// Free Memory
free(node);
}
// ISO File Check
int isPathISO(const char *path)
{
const char *ext;
ext = path + strlen(path) - 4;
if (ext > path)
{
//check extension
if (strcasecmp(ext, ".iso") == 0)
{
return 1;
}
}
return 0;
}
// CSO File Check
int isPathCSO(const char * path)
{
// Result (Not CSO)
int result = 0;
// Open File
SceUID fd = sceIoOpen(path, PSP2_O_RDONLY, 0777);
// Opened File
if(fd >= 0)
{
// Header Buffer
unsigned char header[4];
// Read Header
if(sizeof(header) == sceIoRead(fd, header, sizeof(header)))
{
// CSO Header Magic
unsigned char isoFlags[4] = {
0x43, 0x49, 0x53, 0x4F
};
// Valid Magic
if(0 == memcmp(header, isoFlags, sizeof(header)))
{
// CSO File
result = 1;
}
}
// Close File
sceIoClose(fd);
}
// Return Result
return result;
}
// Game ISO File Check (this crashes for some reason...)
int isGameISO(const char * path)
{
// ISO or CSO File
if(isPathISO(path) || isPathCSO(path))
{
// Game ISO
return 1;
}
// Something else...
return 0;
}
int getRunlevelMode(int mode)
{
switch(mode)
{
case MODE_HOMEBREW:
return HOMEBREW_RUNLEVEL;
case MODE_ISO:
return ISO_RUNLEVEL;
case MODE_POPS:
return POPS_RUNLEVEL;
}
return -1;
}
// Start Application
void start(void)
{
// Find File
File * file = findindex(position);
// Not a valid file
if(file == NULL || file->isFolder) return;
}
// Delete Application
int delete(void)
{
// Find File
File * file = findindex(position);
// Not found
if(file == NULL) return -1;
if(strcmp(file->name, "..") == 0) return -2;
// File Path
char path[1024];
// Puzzle Path
strcpy(path, cwd);
strcpy(path + strlen(path), file->name);
// Delete Folder
if(file->isFolder)
{
// Add Trailing Slash
path[strlen(path) + 1] = 0;
path[strlen(path)] = '/';
// Delete Folder
return delete_folder_recursive(path);
}
// Delete File
else return sceIoRemove(path);
}
// Navigate to Folder
int navigate(void)
{
// Find File
File * file = findindex(position);
// Not a Folder
if(file == NULL || !file->isFolder) return -1;
// Special Case ".."
if(strcmp(file->name, "..") == 0)
{
// Slash Pointer
char * slash = NULL;
// Find Last '/' in Working Directory
int i = strlen(cwd) - 2; for(; i >= 0; i--)
{
// Slash discovered
if(cwd[i] == '/')
{
// Save Pointer
slash = cwd + i + 1;
// Stop Search
break;
}
}
// Terminate Working Directory
slash[0] = 0;
}
// Normal Folder
else
{
// Append Folder to Working Directory
strcpy(cwd + strlen(cwd), file->name);
cwd[strlen(cwd) + 1] = 0;
cwd[strlen(cwd)] = '/';
}
// Return Success
return 0;
}
// Copy File or Folder
void copy(int flag)
{
// Find File
File * file = findindex(position);
// Not found
if(file == NULL) return;
// Copy File Source
strcpy(copysource, cwd);
strcpy(copysource + strlen(copysource), file->name);
// Add Recursive Folder Flag
if(file->isFolder) flag |= COPY_FOLDER_RECURSIVE;
// Set Copy Flags
copymode = flag;
}
// Paste File or Folder
int paste(void)
{
// No Copy Source
if(copymode == NOTHING_TO_COPY) return -1;
// Source and Target Folder are identical
char * lastslash = NULL; int i = 0; for(; i < strlen(copysource); i++) if(copysource[i] == '/') lastslash = copysource + i;
char backup = lastslash[1];
lastslash[1] = 0;
int identical = strcmp(copysource, cwd) == 0;
lastslash[1] = backup;
if(identical) return -2;
// Source Filename
char * filename = lastslash + 1;
// Required Target Path Buffer Size
int requiredlength = strlen(cwd) + strlen(filename) + 1;
// Allocate Target Path Buffer
char * copytarget = (char *)malloc(requiredlength);
// Puzzle Target Path
strcpy(copytarget, cwd);
strcpy(copytarget + strlen(copytarget), filename);
// Return Result
int result = -3;
// Recursive Folder Copy
if((copymode & COPY_FOLDER_RECURSIVE) == COPY_FOLDER_RECURSIVE)
{
// Check Files in current Folder
File * node = files; for(; node != NULL; node = node->next)
{
// Found a file matching the name (folder = ok, file = not)
if(strcmp(filename, node->name) == 0 && !node->isFolder)
{
// Error out
return -4;
}
}
// Copy Folder recursively
result = copy_folder_recursive(copysource, copytarget);
// Source Delete
if(result == 0 && (copymode & COPY_DELETE_ON_FINISH) == COPY_DELETE_ON_FINISH)
{
// Append Trailing Slash (for recursion to work)
copysource[strlen(copysource) + 1] = 0;
copysource[strlen(copysource)] = '/';
// Delete Source
delete_folder_recursive(copysource);
}
}
// Simple File Copy
else
{
// Copy File
result = copy_file(copysource, copytarget);
// Source Delete
if(result == 0 && (copymode & COPY_DELETE_ON_FINISH) == COPY_DELETE_ON_FINISH)
{
// Delete File
sceIoRemove(copysource);
}
}
// Paste Success
if(result == 0)
{
// Erase Cache Data
memset(copysource, 0, sizeof(copysource));
copymode = NOTHING_TO_COPY;
}
// Free Target Path Buffer
free(copytarget);
// Return Result
return result;
}
// Find File Information by Index
File * findindex(int index)
{
// File Iterator Variable
int i = 0;
// Find File Item
File * file = files; for(; file != NULL && i != index; file = file->next) i++;
// Return File
return file;
}
// Delete Folder (recursively)
int delete_folder_recursive(char * path)
{
// Internal File List
File * filelist = NULL;
// Open Working Directory
int directory = sceIoDopen(path);
// Opened Directory
if(directory >= 0)
{
// File Info Read Result
int dreadresult = 1;
// Iterate Files
while(dreadresult > 0)
{
// File Info
SceIoDirent info;
// Clear Memory
memset(&info, 0, sizeof(info));
// Read File Data
dreadresult = sceIoDread(directory, &info);
// Read Success
if(dreadresult >= 0)
{
// Valid Filename
if(strlen(info.d_name) > 0)
{
if(strcmp(info.d_name, ".") == 0 || strcmp(info.d_name, "..") == 0)
{
continue;
}
// Allocate Memory
File * item = (File *)malloc(sizeof(File));
// Clear Memory
memset(item, 0, sizeof(File));
// Copy File Name
strcpy(item->name, info.d_name);
// Set Folder Flag
item->isFolder = PSP2_S_ISDIR(info.d_stat.st_mode);
// New List
if(filelist == NULL) filelist = item;
// Existing List
else
{
// Iterator Variable
File * list = filelist;
// Append to List
while(list->next != NULL) list = list->next;
// Link Item
list->next = item;
}
}
}
}
// Close Directory
sceIoDclose(directory);
}
// List Node
File * node = filelist;
// Iterate Files
for(; node != NULL; node = node->next)
{
// Directory
if(node->isFolder)
{
// Required Buffer Size
int size = strlen(path) + strlen(node->name) + 2;
// Allocate Buffer
char * buffer = (char *)malloc(size);
// Combine Path
strcpy(buffer, path);
strcpy(buffer + strlen(buffer), node->name);
buffer[strlen(buffer) + 1] = 0;
buffer[strlen(buffer)] = '/';
// Recursion Delete
delete_folder_recursive(buffer);
// Free Memory
free(buffer);
}
// File
else
{
// Required Buffer Size
int size = strlen(path) + strlen(node->name) + 1;
// Allocate Buffer
char * buffer = (char *)malloc(size);
// Combine Path
strcpy(buffer, path);
strcpy(buffer + strlen(buffer), node->name);
// Delete File
sceIoRemove(buffer);
// Free Memory
free(buffer);
}
}
// Free temporary List
recursiveFree(filelist);
// Delete now empty Folder
return sceIoRmdir(path);
}
// Copy File from A to B
int copy_file(char * a, char * b)
{
// Chunk Size
int chunksize = 512 * 1024;
// Reading Buffer
char * buffer = (char *)malloc(chunksize);
// Accumulated Writing
int totalwrite = 0;
// Accumulated Reading
int totalread = 0;
// Result
int result = 0;
// Open File for Reading
int in = sceIoOpen(a, PSP2_O_RDONLY, 0777);
// Opened File for Reading
if(in >= 0)
{
// Delete Output File (if existing)
sceIoRemove(b);
// Open File for Writing
int out = sceIoOpen(b, PSP2_O_WRONLY | PSP2_O_CREAT, 0777);
// Opened File for Writing
if(out >= 0)
{
// Read Byte Count
int read = 0;
// Copy Loop (512KB at a time)
while((read = sceIoRead(in, buffer, chunksize)) > 0)
{
// Accumulate Read Data
totalread += read;
// Write Data
totalwrite += sceIoWrite(out, buffer, read);
}
// Close Output File
sceIoClose(out);
// Insufficient Copy
if(totalread != totalwrite) result = -3;
}
// Output Open Error
else result = -2;
// Close Input File