void package_drawable(char*path) { FILE*file=NULL; DRAWABLE_ID=BASE_CHARACTER_ID; mkdir("./libpuzzle"); mkdir("./libpuzzle/src/"); mkdir("./libpuzzle/src/resource_manager"); mkdir("./libpuzzle/src/resource_manager/drawables"); file=fopen("./libpuzzle/src/resource_manager/drawables/R_drawable.h","w"); fprintf(file,"#ifndef __R_DRAWABLE_H__\n"); fprintf(file,"#define __R_DRAWABLE_H__\n\n\n"); fclose(file); file=fopen(DRAWABLE_PKG_NAME,"wb"); if(file) { fclose(file); } trans_directory(path,package_drawable_file); init_parse_character_xml(DRAWABLE_ID); trans_directory(path,package_drawable_xml); exit_parse_character_xml(); file=fopen("./libpuzzle/src/resource_manager/drawables/R_drawable.h","at+"); fseek(file,0,2); fprintf(file,"\n#endif\n"); fclose(file); RESOURCE_INDEX.count=0; { // build res index int size,record_size; char*buffer,*walk; file=drawable_open(); fseek(file,0,2); size=ftell(file); fseek(file,0,0); if(size<=0) { return; } buffer=my_malloc(size); fread(buffer,size,1,file); fclose(file); walk=buffer; while(walk<(buffer+size)) { record_size=*(int*)walk; RESOURCE_INDEX.resource_indexs[RESOURCE_INDEX.count]=((unsigned int)walk)-((unsigned int)buffer); RESOURCE_INDEX.count++; walk+=record_size; } file=fopen(DRAWABLE_PKG_NAME,"wb"); fwrite(&RESOURCE_INDEX.count,4,1,file); fwrite(RESOURCE_INDEX.resource_indexs,RESOURCE_INDEX.count*sizeof(unsigned int),1,file); fwrite(buffer,size,1,file); fclose(file); my_free(buffer); } }
static void trans_directory(char*lpPath,void (*run)(char*name)) { char szFind[MAX_PATH],szFile[MAX_PATH]; WIN32_FIND_DATA FindFileData; HANDLE hFind; strcpy(szFind,lpPath); memcpy(directory,szFind,strlen(szFind)+1); strcat(szFind,"\\*.*"); hFind=FindFirstFile(szFind,&FindFileData); if(INVALID_HANDLE_VALUE == hFind) return; while(TRUE) { if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(FindFileData.cFileName[0]!='.') { strcpy(szFile,lpPath); strcat(szFile,"\\"); strcat(szFile,FindFileData.cFileName); trans_directory(szFile,run); } } else { run(FindFileData.cFileName); } if(!FindNextFile(hFind,&FindFileData)) break; } }
void package_string_table(char**name,int count) { package_name=name; package_count=count/3; package_lan_name=name+package_count; package_lan_code_page=name+package_count*2; package_lan_version=name[count-2]; LANG_PACKAGE_NAME=name[count-1]; builder_strings_table_header(); trans_directory("./",package_string_table_file); buidler_end(); }
int main() { FILE *fd_rec; int rec_level = 3; unsigned char *si, *ei; char opt[300] = { "" }, dir[300] = { "" }, output_dir[300] = { "" }, full_path[300] = { "D:\\GoogleDrive\\Dropbox\\PROGRAM\\for_git\\BS2_Backup_Data\\gem\\brd\\NCTU_KendoTK\\.DIR" }, board[16] = { "" }; do { printf("Please input .DIR file path: \n"); scanf("%s",full_path); si = strstr(full_path,".DIR"); }while(!si); if (full_path[0] == '\"') strncpy(dir, full_path + 1, strlen(full_path) - 2 - 4); else strncpy(dir, full_path, strlen(full_path) - 4); printf("%s\n", dir); ei = strchr(full_path, '\\'); while (strchr(ei + 1, '\\')) { si = ei; ei = strchr(si + 1, '\\'); } strncpy(board, si + 1, ei - si - 1); printf("Board = %s\n", board); printf("目錄檔\n0.不紀錄\n1.紀錄一層\n3.全部紀錄(適用精華區)\n請選擇 : "); scanf("%d",&rec_level); if (rec_level < 0) rec_level = 0; else if (rec_level >= 3) rec_level = INT_MAX; sprintf(output_dir, "BBS_backup\\%s\\", board); sprintf(opt, "mkdir \"%s\"", output_dir); system(opt); if (rec_level > 0) { sprintf(opt, "%sdirectory.txt", output_dir); fd_rec = fopen(opt, "w"); if (!fd_rec) { printf("Writing record file failed, %s\npath : \"%s\"\n", strerror(errno), opt); system("pause"); return -1; } } sprintf(output_dir, "%scontent\\", output_dir); trans_directory(dir, full_path, output_dir, rec_level, fd_rec); if (rec_level > 0) fclose(fd_rec); printf("Finish!\n"); system("pause"); return 0; }
int trans_directory(const char* fn_dir, const char* fn_i, const char* backup_dir, const int rec_level, const char* fd_rec) { int i = 0, size, pad, result; unsigned char *si, *ei, *title, is_dir; unsigned char ID[80], name[50], date[9], title0[73 + 3] = { 0xa1,0xbb,' ' }; unsigned char file_path[300] = { "7\\A1234567" }, prop[12]; unsigned char *file = &(file_path[2]); FILE *fd_i; // directory fi char full_path[300] = { "" }, opt[300] = { "" }; fd_i = fopen(fn_i, "rb"); if (!fd_i) { printf("Loading directory file failed, %s\npath : \"%s\"\n", strerror(errno), fn_i); return -1; } fseek(fd_i, 0, SEEK_END); size = ftell(fd_i); // file size fseek(fd_i, 0, SEEK_SET); pad = (int)log10(size / 256) + 1; sprintf(opt, "mkdir \"%s\"", backup_dir); system(opt); while (++i) { fread(prop, sizeof(char), 12, fd_i); is_dir = (prop[6] == 0x01); if (fread(file, sizeof(char), 32, fd_i) <= 0) break; fread(ID, sizeof(char), 80, fd_i); si = strchr(ID, '.'); // [email protected] F if (si) *(si + 1) = '\0'; fread(name, sizeof(char), 50, fd_i); fseek(fd_i, 3, SEEK_CUR); // skip year fread(date, sizeof(char), 6, fd_i); fread(title0 + 3, sizeof(char), 73, fd_i); //++(square symbol) when ! Re if (!strncmp(title0 + 3, "Re: ", 4)) { // in order to edit "Re: " to "Re " title = title0 + 4; // e: ... title[0] = 'R'; title[1] = 'e'; } else { // not Re: adding square symbol if (is_dir) title0[1] = 0xbb; // ◆ else title0[1] = 0xba; title0[0] = 0xa1; title0[2] = ' '; title = title0; } if (file[0] == '@') file_path[0] = '@'; else file_path[0] = file[7]; sprintf(full_path, "%s%c\\%s", fn_dir, file_path[0], file); date[2] = '_'; // file name can't content '/' fix_file_name(title + 2); // replace other invalid char with space memset(file_path, '\0', sizeof(file_path)); // Here you can change the filename's formate of output file. if (strlen(date)) sprintf(file_path, "%s\\%0*d . %s . %s", backup_dir, pad, i, date, title); else sprintf(file_path, "%s\\%0*d . %s", backup_dir, pad, i, title); if (!is_dir) { sprintf(file_path, "%s.txt", file_path); result = trans_file(full_path, file_path); } else result = trans_directory(fn_dir, full_path, file_path, rec_level - 1, fd_rec); // only record at first time if (rec_level > 0) { fprintf(fd_rec, "%8s %6d %5s %-13s %-46s", full_path + strlen(full_path) - 10, i, date, ID, title); if (result) fprintf(fd_rec, "\t解析失敗!\n"); else fprintf(fd_rec, "\n"); } } fclose(fd_i); }