Add target_save

This commit is contained in:
Alexander Batalov 2023-09-02 17:19:51 +03:00
parent 96573a7209
commit 05b4c125e6
2 changed files with 42 additions and 0 deletions

View File

@ -139,6 +139,47 @@ int target_header_load()
return 0; return 0;
} }
// 0x49B58C
int target_save(int pid)
{
char path[COMPAT_MAX_PATH];
size_t len;
char* extension;
FILE* stream;
TargetSubNode* subnode;
if (target_ptr(pid, &subnode) == -1) {
return -1;
}
target_make_path(path, pid);
len = strlen(path);
path[len] = '\\';
_proto_list_str(pid, path + len + 1);
extension = strchr(path + len + 1, '.');
if (extension != NULL) {
strcpy(extension + 1, "tgt");
} else {
strcat(path, ".tgt");
}
stream = fopen(path, "wb");
if (stream == NULL) {
return -1;
}
while (subnode != NULL) {
fwrite(subnode, sizeof(TargetSubNode), 1, stream);
subnode = subnode->next;
}
fclose(stream);
return 0;
}
// 0x49B6BC // 0x49B6BC
int target_load(int pid, TargetSubNode** subnode_ptr) int target_load(int pid, TargetSubNode** subnode_ptr)
{ {

View File

@ -53,6 +53,7 @@ int target_init();
int target_exit(); int target_exit();
int target_header_save(); int target_header_save();
int target_header_load(); int target_header_load();
int target_save(int pid);
int target_load(int pid, TargetSubNode** subnode_ptr); int target_load(int pid, TargetSubNode** subnode_ptr);
int target_find_free_subnode(TargetSubNode** subnode_ptr); int target_find_free_subnode(TargetSubNode** subnode_ptr);
int target_remove_all(); int target_remove_all();