Skip to content

Commit 26ddf79

Browse files
authored
Add cloud save ftp sync (#215)
* add ftp * add options * move sqlite * upload saves * download to hdd * improvements
1 parent db13d7a commit 26ddf79

20 files changed

Lines changed: 1454 additions & 674 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313

1414
jobs:
1515
build_pkg:
16-
runs-on: ubuntu-20.04
16+
runs-on: ubuntu-22.04
1717
steps:
1818

1919
- name: Checkout

include/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int unlink_secure(const char *path);
2020
int mkdirs(const char* dir);
2121
int copy_file(const char* input, const char* output);
2222
int copy_directory(const char* startdir, const char* inputdir, const char* outputdir);
23-
int clean_directory(const char* inputdir);
23+
int clean_directory(const char* inputdir, const char* filter);
2424
uint32_t file_crc32(const char* input);
2525

2626
#endif

include/saves.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ enum cmd_code_enum
9696
CMD_COPY_PFS,
9797
CMD_IMPORT_DATA_FILE,
9898
CMD_DELETE_SAVE,
99+
CMD_UPLOAD_SAVE,
99100

100101
// Bulk commands
101102
CMD_RESIGN_SAVES,
@@ -158,13 +159,14 @@ enum cmd_code_enum
158159
enum save_type_enum
159160
{
160161
FILE_TYPE_NULL,
162+
FILE_TYPE_PS1,
163+
FILE_TYPE_PS2,
161164
FILE_TYPE_MENU,
162165
FILE_TYPE_PS4,
163166
FILE_TYPE_TRP,
164167
FILE_TYPE_VMC,
165168

166169
// PS1 File Types
167-
FILE_TYPE_PS1,
168170
FILE_TYPE_PSX,
169171
FILE_TYPE_MCS,
170172

@@ -179,7 +181,6 @@ enum save_type_enum
179181
FILE_TYPE_ACT,
180182

181183
// PS2 File Types
182-
FILE_TYPE_PS2,
183184
FILE_TYPE_PSU,
184185
FILE_TYPE_MAX,
185186
FILE_TYPE_CBS,
@@ -239,11 +240,11 @@ enum save_sort_enum
239240
typedef struct save_entry
240241
{
241242
char * name;
242-
char * title_id;
243-
char * path;
244-
char * dir_name;
243+
char * title_id;
244+
char * path;
245+
char * dir_name;
245246
uint32_t blocks;
246-
uint16_t flags;
247+
uint16_t flags;
247248
uint16_t type;
248249
list_t * codes;
249250
} save_entry_t;
@@ -253,7 +254,7 @@ typedef struct
253254
list_t * list;
254255
char path[128];
255256
char* title;
256-
uint8_t icon_id;
257+
uint8_t id;
257258
void (*UpdatePath)(char *);
258259
int (*ReadCodes)(save_entry_t *);
259260
list_t* (*ReadList)(const char*);
@@ -282,11 +283,14 @@ int ReadVmc2Codes(save_entry_t * save);
282283
int http_init(void);
283284
void http_end(void);
284285
int http_download(const char* url, const char* filename, const char* local_dst, int show_progress);
286+
int ftp_upload(const char* local_file, const char* url, const char* filename, int show_progress);
285287

286288
int extract_7zip(const char* zip_file, const char* dest_path);
287289
int extract_rar(const char* rar_file, const char* dest_path);
288290
int extract_zip(const char* zip_file, const char* dest_path);
289291
int zip_directory(const char* basedir, const char* inputdir, const char* output_zipfile);
292+
int zip_file(const char* input, const char* output_zipfile);
293+
int extract_sfo(const char* zip_file, const char* dest_path);
290294

291295
int show_dialog(int dialog_type, const char * format, ...);
292296
int osk_dialog_get_text(const char* title, char* text, uint32_t size);
@@ -300,6 +304,10 @@ void stop_loading_screen(void);
300304

301305
void execCodeCommand(code_entry_t* code, const char* codecmd);
302306

307+
void* open_sqlite_db(const char* db_path);
308+
int save_sqlite_db(void* db, const char* db_path);
309+
int get_appdb_title(void* db, const char* titleid, char* name);
310+
int get_name_title_id(const char* titleid, char* name);
303311
int appdb_rebuild(const char* db_path, uint32_t userid);
304312
int appdb_fix_delete(const char* db_path, uint32_t userid);
305313
int addcont_dlc_rebuild(const char* db_path);

include/settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ typedef struct
3333
uint8_t doAni;
3434
uint8_t update;
3535
uint8_t usb_dev;
36+
uint8_t online_opt;
3637
uint8_t dbglog;
3738
uint32_t user_id;
3839
uint64_t psid[2];
3940
uint64_t account_id;
4041
char save_db[256];
42+
char ftp_url[512];
4143
} app_config_t;
4244

4345
extern menu_option_t menu_options[];

include/svpng.h

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright (C) 2017 Milo Yip. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
* Neither the name of pngout nor the names of its
15+
contributors may be used to endorse or promote products derived from
16+
this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/*! \file
31+
\brief svpng() is a minimalistic C function for saving RGB/RGBA image into uncompressed PNG.
32+
\author Milo Yip
33+
\version 0.1.1
34+
\copyright MIT license
35+
\sa http://github.com/miloyip/svpng
36+
*/
37+
38+
#ifndef SVPNG_INC_
39+
#define SVPNG_INC_
40+
41+
/*! \def SVPNG_LINKAGE
42+
\brief User customizable linkage for svpng() function.
43+
By default this macro is empty.
44+
User may define this macro as static for static linkage,
45+
and/or inline in C99/C++, etc.
46+
*/
47+
#ifndef SVPNG_LINKAGE
48+
#define SVPNG_LINKAGE static
49+
#endif
50+
51+
/*! \def SVPNG_OUTPUT
52+
\brief User customizable output stream.
53+
By default, it uses C file descriptor and fputc() to output bytes.
54+
In C++, for example, user may use std::ostream or std::vector instead.
55+
*/
56+
#ifndef SVPNG_OUTPUT
57+
#include <stdio.h>
58+
#define SVPNG_OUTPUT FILE* fp
59+
#endif
60+
61+
/*! \def SVPNG_PUT
62+
\brief Write a byte
63+
*/
64+
#ifndef SVPNG_PUT
65+
#define SVPNG_PUT(u) fputc(u, fp)
66+
#endif
67+
68+
69+
/*!
70+
\brief Save a RGB/RGBA image in PNG format.
71+
\param SVPNG_OUTPUT Output stream (by default using file descriptor).
72+
\param w Width of the image. (<16383)
73+
\param h Height of the image.
74+
\param img Image pixel data in 24-bit RGB or 32-bit RGBA format.
75+
\param alpha Whether the image contains alpha channel.
76+
*/
77+
SVPNG_LINKAGE void svpng(SVPNG_OUTPUT, unsigned w, unsigned h, const unsigned char* img, int alpha) {
78+
static const unsigned t[] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
79+
/* CRC32 Table */ 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c };
80+
unsigned a = 1, b = 0, c, p = w * (alpha ? 4 : 3) + 1, x, y, i; /* ADLER-a, ADLER-b, CRC, pitch */
81+
#define SVPNG_U8A(ua, l) for (i = 0; i < l; i++) SVPNG_PUT((ua)[i]);
82+
#define SVPNG_U32(u) do { SVPNG_PUT((u) >> 24); SVPNG_PUT(((u) >> 16) & 255); SVPNG_PUT(((u) >> 8) & 255); SVPNG_PUT((u) & 255); } while(0)
83+
#define SVPNG_U8C(u) do { SVPNG_PUT(u); c ^= (u); c = (c >> 4) ^ t[c & 15]; c = (c >> 4) ^ t[c & 15]; } while(0)
84+
#define SVPNG_U8AC(ua, l) for (i = 0; i < l; i++) SVPNG_U8C((ua)[i])
85+
#define SVPNG_U16LC(u) do { SVPNG_U8C((u) & 255); SVPNG_U8C(((u) >> 8) & 255); } while(0)
86+
#define SVPNG_U32C(u) do { SVPNG_U8C((u) >> 24); SVPNG_U8C(((u) >> 16) & 255); SVPNG_U8C(((u) >> 8) & 255); SVPNG_U8C((u) & 255); } while(0)
87+
#define SVPNG_U8ADLER(u) do { SVPNG_U8C(u); a = (a + (u)) % 65521; b = (b + a) % 65521; } while(0)
88+
#define SVPNG_BEGIN(s, l) do { SVPNG_U32(l); c = ~0U; SVPNG_U8AC(s, 4); } while(0)
89+
#define SVPNG_END() SVPNG_U32(~c)
90+
SVPNG_U8A("\x89PNG\r\n\32\n", 8); /* Magic */
91+
SVPNG_BEGIN("IHDR", 13); /* IHDR chunk { */
92+
SVPNG_U32C(w); SVPNG_U32C(h); /* Width & Height (8 bytes) */
93+
SVPNG_U8C(8); SVPNG_U8C(alpha ? 6 : 2); /* Depth=8, Color=True color with/without alpha (2 bytes) */
94+
SVPNG_U8AC("\0\0\0", 3); /* Compression=Deflate, Filter=No, Interlace=No (3 bytes) */
95+
SVPNG_END(); /* } */
96+
SVPNG_BEGIN("IDAT", 2 + h * (5 + p) + 4); /* IDAT chunk { */
97+
SVPNG_U8AC("\x78\1", 2); /* Deflate block begin (2 bytes) */
98+
for (y = 0; y < h; y++) { /* Each horizontal line makes a block for simplicity */
99+
SVPNG_U8C(y == h - 1); /* 1 for the last block, 0 for others (1 byte) */
100+
SVPNG_U16LC(p); SVPNG_U16LC(~p); /* Size of block in little endian and its 1's complement (4 bytes) */
101+
SVPNG_U8ADLER(0); /* No filter prefix (1 byte) */
102+
for (x = 0; x < p - 1; x += 4, img += 4)
103+
{
104+
SVPNG_U8ADLER(img[3]); /* Image pixel data */
105+
SVPNG_U8ADLER(img[2]); /* Image pixel data */
106+
SVPNG_U8ADLER(img[1]); /* Image pixel data */
107+
SVPNG_U8ADLER(img[0]); /* Image pixel data */
108+
}
109+
}
110+
SVPNG_U32C((b << 16) | a); /* Deflate block end with adler (4 bytes) */
111+
SVPNG_END(); /* } */
112+
SVPNG_BEGIN("IEND", 0); SVPNG_END(); /* IEND chunk {} */
113+
}
114+
115+
#endif /* SVPNG_INC_ */

include/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define ALIGN(_value, _alignment) (((_value) + (_alignment) - 1) & ~((_alignment) - 1))
1111

1212
void dump_data(const u8 *data, u64 size);
13+
void get_psv_filename(char* psvName, const char* path, const char* dirName);
1314

1415
int get_file_size(const char *file_path, u64 *size);
1516
int read_file(const char *file_path, u8 *data, u64 size);

source/common.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int copy_file(const char* input, const char* output)
139139

140140
uint32_t file_crc32(const char* input)
141141
{
142-
char buffer[TMP_BUFF_SIZE];
142+
Bytef *buffer;
143143
uLong crc = crc32(0L, Z_NULL, 0);
144144
size_t read;
145145

@@ -148,13 +148,15 @@ uint32_t file_crc32(const char* input)
148148
if (!in)
149149
return FAILED;
150150

151+
buffer = malloc(TMP_BUFF_SIZE);
151152
do
152153
{
153154
read = fread(buffer, 1, TMP_BUFF_SIZE, in);
154-
crc = crc32(crc, (u8*)buffer, read);
155+
crc = crc32(crc, buffer, read);
155156
}
156157
while (read == TMP_BUFF_SIZE);
157158

159+
free(buffer);
158160
fclose(in);
159161

160162
return crc;
@@ -192,7 +194,7 @@ int copy_directory(const char* startdir, const char* inputdir, const char* outpu
192194
return SUCCESS;
193195
}
194196

195-
int clean_directory(const char* inputdir)
197+
int clean_directory(const char* inputdir, const char* filter)
196198
{
197199
DIR *d;
198200
struct dirent *dir;
@@ -204,13 +206,13 @@ int clean_directory(const char* inputdir)
204206

205207
while ((dir = readdir(d)) != NULL)
206208
{
207-
if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0)
209+
if (strcmp(dir->d_name, ".") != 0 && strcmp(dir->d_name, "..") != 0 && strstr(dir->d_name, filter) != NULL)
208210
{
209211
snprintf(dataPath, sizeof(dataPath), "%s" "%s", inputdir, dir->d_name);
210212

211213
if (dir->d_type == DT_DIR) {
212214
strcat(dataPath, "/");
213-
clean_directory(dataPath);
215+
clean_directory(dataPath, filter);
214216
rmdir(dataPath);
215217
}
216218

source/draw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static void drawJars(uint8_t alpha)
372372
drawJar(jar_hdd_png_index, jar_hdd_png_x, jar_hdd_png_y, (alpha == 0xFF ? "HDD Saves" : ""), alpha);
373373

374374
//Online cheats
375-
drawJar(jar_db_png_index, jar_db_png_x, jar_db_png_y, (alpha == 0xFF ? "Online DB" : ""), alpha);
375+
drawJar(jar_db_png_index, jar_db_png_x, jar_db_png_y, (alpha == 0xFF ? (apollo_config.online_opt ? "FTP Server" : "Online DB") : ""), alpha);
376376

377377
//User Backup
378378
drawJar(jar_bup_png_index, jar_bup_png_x, jar_bup_png_y, (alpha == 0xFF ? "User Tools" : ""), alpha);

0 commit comments

Comments
 (0)