bool File::Create(const char *Name,const wchar *NameW) { /*#ifdef _WIN_32 #ifndef _XBOX if (WinNT() && NameW!=NULL && *NameW!=0) hFile=CreateFileW(NameW,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); else #endif hFile=CreateFile(Name,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); #else hFile=fopen(Name,CREATEBINARY); #endif*/ CStdString strPath; CUtil::GetDirectory(Name,strPath); CUtil::CreateDirectoryEx(strPath); m_File.OpenForWrite(Name,true,true); NewFile=true; HandleType=FILE_HANDLENORMAL; SkipClose=false; if (NameW!=NULL) strcpyw(FileNameW,NameW); else *FileNameW=0; if (Name!=NULL) strcpy(FileName,Name); else WideToChar(NameW,FileName); //AddFileToList(hFile); AddFileToList(); //return(hFile!=BAD_HANDLE); return true; }
bool File::Create(const char *Name,const wchar *NameW) { /*#ifdef _WIN_32 if (WinNT() && NameW!=NULL && *NameW!=0) hFile=CreateFileW(NameW,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); else hFile=CreateFile(Name,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); #else*/ hFile=fopen(Name,CREATEBINARY); //#endif NewFile=true; HandleType=FILE_HANDLENORMAL; SkipClose=false; if (NameW!=NULL) strcpyw(FileNameW,NameW); else *FileNameW=0; if (Name!=NULL) strcpy(FileName,Name); else WideToChar(NameW,FileName); AddFileToList(hFile); return(hFile!=BAD_HANDLE); }
int FillAvatarListFromFolder(HWND list, MCONTACT hContact) { int max_pos = 0; TCHAR dir[MAX_PATH], path[MAX_PATH]; WIN32_FIND_DATA finddata; GetContactFolder(dir, hContact); mir_sntprintf(path, _countof(path), _T("%s\\*.lnk"), dir); HANDLE hFind = FindFirstFile(path, &finddata); if (hFind == INVALID_HANDLE_VALUE) return 0; do { if (finddata.cFileName[0] != '.') { TCHAR lnk[MAX_PATH]; mir_sntprintf(lnk, _countof(lnk), _T("%s\\%s"), dir, finddata.cFileName); if (ResolveShortcut(lnk, path)) max_pos = AddFileToList(path,lnk,finddata.cFileName,list); } } while(FindNextFile(hFind, &finddata)); FindClose(hFind); SendMessage(list, LB_SETCURSEL, max_pos, 0); // Set to first item return 0; }
CFileTree::CFileTree() : m_pFileList(0), m_nFiles(0) { CScriptFile file; file.SetFile("ExampleScript.txt"); AddFileToList(file); }
bool File::Create(const char *Name,const wchar *NameW) { // Below commented code was left behind on spiffs request for possible later usage /*#ifdef _WIN_32 #ifndef _XBOX if (WinNT() && NameW!=NULL && *NameW!=0) hFile=CreateFileW(NameW,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); else #endif hFile=CreateFile(Name,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL, CREATE_ALWAYS,0,NULL); #else hFile=fopen(Name,CREATEBINARY); #endif*/ char name[NM]; if (NameW) WideToUtf(NameW, name, NM); else strcpy(name, Name); char* lastslash = strrchr(name, '\\'); char tmp; if (!lastslash) lastslash = strrchr(name, '/'); if (lastslash) { tmp = *lastslash; *lastslash = '\0'; } XBMC->CreateDirectory(name); *lastslash = tmp; m_File = XBMC->OpenFileForWrite(name, true); NewFile=true; HandleType=FILE_HANDLENORMAL; SkipClose=false; if (NameW!=NULL) strcpyw(FileNameW,NameW); else *FileNameW=0; if (Name!=NULL) strcpy(FileName,Name); else WideToChar(NameW,FileName); //AddFileToList(hFile); AddFileToList(); //return(hFile!=BAD_HANDLE); return true; }
bool File::Open(const char *Name,const wchar *NameW,bool OpenShared,bool Update) { /*ErrorType=FILE_SUCCESS; FileHandle hNewFile; if (File::OpenShared) OpenShared=true; #ifdef _WIN_32 uint Access=GENERIC_READ; if (Update) Access|=GENERIC_WRITE; uint ShareMode=FILE_SHARE_READ; if (OpenShared) ShareMode|=FILE_SHARE_WRITE; #ifndef _XBOX if (WinNT() && NameW!=NULL && *NameW!=0) hNewFile=CreateFileW(NameW,Access,ShareMode,NULL,OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,NULL); else #endif hNewFile=CreateFile(Name,Access,ShareMode,NULL,OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN,NULL); if (hNewFile==BAD_HANDLE && GetLastError()==ERROR_FILE_NOT_FOUND) ErrorType=FILE_NOTFOUND; #else int flags=Update ? O_RDWR:O_RDONLY; #ifdef O_BINARY flags|=O_BINARY; #if defined(_AIX) && defined(_LARGE_FILE_API) flags|=O_LARGEFILE; #endif #endif #if defined(_EMX) && !defined(_DJGPP) int sflags=OpenShared ? SH_DENYNO:SH_DENYWR; int handle=sopen(Name,flags,sflags); #else int handle=open(Name,flags); #ifdef LOCK_EX if (!OpenShared && Update && handle>=0 && flock(handle,LOCK_EX|LOCK_NB)==-1) { close(handle); return(false); } #endif #endif hNewFile=handle==-1 ? BAD_HANDLE:fdopen(handle,Update ? UPDATEBINARY:READBINARY); if (hNewFile==BAD_HANDLE && errno==ENOENT) ErrorType=FILE_NOTFOUND; #endif NewFile=false; HandleType=FILE_HANDLENORMAL; SkipClose=false; bool success=hNewFile!=BAD_HANDLE;*/ bool success; if (Update) success = m_File.OpenForWrite(Name); else success = m_File.Open(Name); if (success) { // hFile=hNewFile; if (NameW!=NULL) strcpyw(FileNameW,NameW); else *FileNameW=0; if (Name!=NULL) strcpy(FileName,Name); else WideToChar(NameW,FileName); //AddFileToList(hFile); AddFileToList(); } return(success); }
int main(void) { filelist bg, tileset, npcset; FILE *fp; int i, j; char *comma; char buf[256]; // read data from exe fp = fopen("/data/win/Programs/Games/Cave Story Deluxe/CaveStory/Doukutsu.exe", "rb"); if (!fp) { printf("Failed opening exe\n"); return 1; } // load raw data into struct fseek(fp, DATA_OFFSET, SEEK_SET); fread(MapData, sizeof(MapRecord), NMAPS, fp); fclose(fp); // parse tileset and bg info and convert strings to numbers memset(&bg, 0, sizeof(bg)); memset(&tileset, 0, sizeof(tileset)); memset(&npcset, 0, sizeof(npcset)); for(i=0;i<NMAPS;i++) { AddFileToList(&bg, MapData[i].background); AddFileToList(&tileset, MapData[i].tileset); AddFileToList(&npcset, MapData[i].NPCset1); AddFileToList(&npcset, MapData[i].NPCset2); } // output data to .c & .h file fp = fopen("../autogen/stagedata.h", "wb"); fprintf(fp, "//auto-generated by extractmapinfo.c\n\n"); fprintf(fp, "#define NMAPS\t %d\n", NMAPS); fprintf(fp, "typedef struct\n"); fprintf(fp, "{\n"); fprintf(fp, "\tchar filename[32];\n"); fprintf(fp, "\tchar stagename[35];\n\n"); fprintf(fp, "\tuint8_t tileset;\n"); fprintf(fp, "\tuint8_t bg_no;\n"); fprintf(fp, "\tuint8_t scroll_type;\n"); fprintf(fp, "\tuint8_t bossNo;\n"); fprintf(fp, "\tuint8_t NPCset1;\n"); fprintf(fp, "\tuint8_t NPCset2;\n"); fprintf(fp, "} MapRecord;\n\n"); fprintf(fp, "extern MapRecord stages[NMAPS];\n\n"); fprintf(fp, "#define NUM_BACKDROPS %d\n", bg.nfiles); fprintf(fp, "#define NUM_TILESETS %d\n\n", tileset.nfiles); fprintf(fp, "extern const char *backdrop_names[];\n"); fprintf(fp, "extern const char *tileset_names[];\n"); // output the NPC spriteset constants fprintf(fp, "\n\n"); for(i=0;i<npcset.nfiles;i++) { // make the filename upper-case so it looks like a constant for(j=strlen(npcset.files[i])-1;j>=0;j--) { npcset.files[i][j] = toupper(npcset.files[i][j]); } fprintf(fp, "#define NPCSET_%s\t\t %d\n", npcset.files[i], i); } fprintf(fp, "\n"); fclose(fp); fp = fopen("../autogen/stagedata.cpp", "wb"); fprintf(fp, "//auto-generated by extractmapinfo.c\n\n"); fprintf(fp, "#include <stdio.h>\n"); fprintf(fp, "#include <stdint.h>\n"); fprintf(fp, "#include \"stagedata.h\"\n\n"); // output the backdrop names fprintf(fp, "const char *backdrop_names[] = {\n"); for(i=0;i<bg.nfiles;i++) { bg.files[i][0] = tolower(bg.files[i][0]); // fix case-sensitivity issue on UNIX filesystems fprintf(fp, "\t\"%s\",\n", bg.files[i]); } fprintf(fp, "\tNULL\n};\n\n"); // output the tileset names fprintf(fp, "const char *tileset_names[] = {\n"); for(i=0;i<tileset.nfiles;i++) { fprintf(fp, "\t\"%s\",\n", tileset.files[i]); } fprintf(fp, "\tNULL\n};\n\n"); // finally output the map records fprintf(fp, "MapRecord stages[NMAPS] = {\n"); comma = ","; for(i=0;i<NMAPS;i++) { if (i+1==NMAPS) comma = ""; fprintf(fp, "\"%s\", \"%s\", %d, %d, %d, %d, %d, %d%s\n", \ MapData[i].filename, \ MapData[i].caption, \ FindFileInList(&tileset, MapData[i].tileset), \ FindFileInList(&bg, MapData[i].background), \ MapData[i].scroll_type, \ MapData[i].bossNo, \ FindFileInList(&npcset, MapData[i].NPCset1), \ FindFileInList(&npcset, MapData[i].NPCset2), \ comma); } fprintf(fp, "};\n\n"); fclose(fp); return 0; }