T_BOOL Fwl_FileExist(T_pCWSTR path) { T_hFILE pFile = 0; T_BOOL ret = AK_FALSE; if (AK_NULL != path) { pFile = File_OpenUnicode((T_hFILE)AK_NULL, path, FILE_MODE_READ); if (FS_INVALID_HANDLE == pFile) { pFile = File_OpenUnicode((T_hFILE)AK_NULL, path, FILE_MODE_ASYN | FILE_MODE_READ); if (FS_INVALID_HANDLE == pFile) { //AK_DEBUG_OUTPUT("FWL FILE ERROR: Fwl_FileExist:open fail %d\n", pFile); return AK_FALSE; } } ret = File_Exist(pFile); File_Close(pFile); } return ret; }
T_BOOL Fwl_FileStatEx(T_hFILE hFile, T_hFILEINFO hFileInfo) { T_PFILEINFO pFileInfo = (T_PFILEINFO)hFileInfo; if (FS_INVALID_HANDLE == hFile || AK_NULL == pFileInfo) { return AK_FALSE; } if (!File_Exist(hFile)) { return AK_FALSE; } File_GetFileinfo(hFile, pFileInfo); return AK_TRUE; }
T_BOOL Fwl_FileStat(T_pCWSTR path, T_hFILEINFO hFileInfo) { T_hFILE file = 0; T_PFILEINFO pFileInfo = (T_PFILEINFO)hFileInfo; if (AK_NULL == pFileInfo) { return AK_FALSE; } file = File_OpenUnicode((T_hFILE)AK_NULL, path, FILE_MODE_READ); if (!File_Exist(file)) { File_Close(file); return AK_FALSE; } File_GetFileinfo(file, pFileInfo); File_Close(file); return AK_TRUE; }
T_hFILE Fwl_FileOpen(T_pCWSTR path, T_FILE_FLAG flag, T_FILE_MODE attr) { T_hFILE file = FS_INVALID_HANDLE; file = File_OpenUnicode((T_hFILE)AK_NULL, path, flag); if (!File_Exist(file)) { /* Whatever mode you open the file, it fails when it doesn't exist. */ File_Close(file); return FS_INVALID_HANDLE; } /* Application layer shouldn't open a folder! */ if (File_IsFolder(file)) { File_Close(file); return FS_INVALID_HANDLE; } return (T_hFILE)file; }
// ------------------------------------------------------ // Handle left mouse button void Mouse_Left_DiskIO_Ed(void) { int i; char WavFileName[MAX_PATH]; if(userscreen == USER_SCREEN_DISKIO_EDIT) { // Save song if(zcheckMouse(8, (Cur_Height - 112), 80, 16)) { #ifndef __LITE__ if(File_Exist_Req("%s"SLASH"%s.ptk", Dir_Mods, name)) #else if(File_Exist_Req("%s"SLASH"%s.ptl", Dir_Mods, name)) #endif { Display_Requester(&Overwrite_Requester, GUI_CMD_SAVE_MODULE); } else { gui_action = GUI_CMD_SAVE_MODULE; } } // Save final if(zcheckMouse(254, (Cur_Height - 130), 80, 16)) { if(File_Exist_Req("%s"SLASH"%s.ptp", Dir_Mods, name)) { Display_Requester(&Overwrite_Requester, GUI_CMD_SAVE_FINAL); } else { gui_action = GUI_CMD_SAVE_FINAL; } } // Calc final if(zcheckMouse(254, (Cur_Height - 112), 80, 16)) { gui_action = GUI_CMD_CALC_FINAL; } // Calc length if(zcheckMouse(254, (Cur_Height - 76), 80, 16)) { Calc_Length(); } if(zcheckMouse(90, (Cur_Height - 130), 80, 16)) { gui_action = GUI_CMD_MODULE_INFOS; } // Start module name input if(zcheckMouse(90, (Cur_Height - 94), 162, 16) && snamesel == INPUT_NONE) { strcpy(cur_input_name, name); sprintf(name, ""); namesize = 0; snamesel = INPUT_MODULE_NAME; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Start artist name input if(zcheckMouse(90, (Cur_Height - 76), 162, 16) && snamesel == INPUT_NONE) { strcpy(cur_input_name, artist); sprintf(artist, ""); namesize = 0; snamesel = INPUT_MODULE_ARTIST; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Start module style input if(zcheckMouse(90, (Cur_Height - 58), 162, 16) && snamesel == INPUT_NONE) { strcpy(cur_input_name, style); sprintf(style, ""); namesize = 0; snamesel = INPUT_MODULE_STYLE; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Zzaapp if(zcheckMouse(8, (Cur_Height - 130), 80, 16)) { Display_Requester(&Zzaapp_Requester, GUI_CMD_NEW_MODULE); } if(zcheckMouse(90, (Cur_Height - 112), 80, 16)) { if(rawrender_target == RENDER_TO_FILE) { if(rawrender_multi && rawrender_target == RENDER_TO_FILE) { int any_file = FALSE; for(i = 0; i < Songtracks; i++) { sprintf(WavFileName, "%%s"SLASH"%%s_%x.wav", i); if(File_Exist(WavFileName, Dir_Mods, name)) { any_file = TRUE; break; } } if(any_file) { Overwrite_Requester.Text = "Some .wav files are about to be overwritten, is that ok ?"; Display_Requester(&Overwrite_Requester, GUI_CMD_RENDER_WAV); } else { gui_action = GUI_CMD_RENDER_WAV; } } else { if(File_Exist_Req("%s"SLASH"%s.wav", Dir_Mods, name)) { Display_Requester(&Overwrite_Requester, GUI_CMD_RENDER_WAV); } else { gui_action = GUI_CMD_RENDER_WAV; } } } else { gui_action = GUI_CMD_RENDER_WAV; } } // Render as 32 bit on if(zcheckMouse(458, (Cur_Height - 68), 29, 16) && !Allow_32bit) { rawrender_32float = TRUE; teac = 1; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render as 32 bit off if(zcheckMouse(458 + 31, (Cur_Height - 68), 29, 16) && !Allow_32bit) { rawrender_32float = FALSE; teac = 1; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render entire song if(zcheckMouse(534, (Cur_Height - 112), 40, 16)) { rawrender_range = FALSE; teac = 0; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render a range if(zcheckMouse(534 + 42, (Cur_Height - 112), 40, 16)) { rawrender_range = TRUE; teac = 0; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } if(rawrender_range) { // From position if(zcheckMouse(572, (Cur_Height - 86), 16, 16) == 1) { rawrender_from--; gui_action = GUI_CMD_UPDATE_DISKIO_ED; teac = 3; } // From position if(zcheckMouse(572 + 44, (Cur_Height - 86), 16, 16) == 1) { rawrender_from++; gui_action = GUI_CMD_UPDATE_DISKIO_ED; teac = 3; } // To position if(zcheckMouse(572, (Cur_Height - 66), 16, 16) == 1) { rawrender_to--; gui_action = GUI_CMD_UPDATE_DISKIO_ED; teac = 4; } // To position if(zcheckMouse(572 + 44, (Cur_Height - 66), 16, 16) == 1) { rawrender_to++; gui_action = GUI_CMD_UPDATE_DISKIO_ED; teac = 4; } } // Render to wav file if(zcheckMouse(654, (Cur_Height - 106), 80, 16)) { rawrender_target = RENDER_TO_FILE; teac = 0; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render to mono sample if(zcheckMouse(654, (Cur_Height - 88), 80, 16)) { rawrender_target = RENDER_TO_MONO; teac = 0; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render to stereo sample if(zcheckMouse(654, (Cur_Height - 70), 80, 16)) { rawrender_target = RENDER_TO_STEREO; teac = 0; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render as multiple file if(zcheckMouse(458, (Cur_Height - 49), 29, 16) && !Allow_Single_Render) { rawrender_multi = TRUE; teac = 5; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } // Render as single files if(zcheckMouse(458 + 31, (Cur_Height - 49), 29, 16) && !Allow_Single_Render) { rawrender_multi = FALSE; teac = 5; gui_action = GUI_CMD_UPDATE_DISKIO_ED; } Check_Tracks_To_Render(); } }
double JEvaluate_Pos(string ARightPosFileName, string ACheckPosFileName, string AResultFileNameSuffix) { if (File_Exist(ARightPosFileName) == false) { cout << "不存在正确词性标注的文件:" << ARightPosFileName << endl; return -1; } if (File_Exist(ACheckPosFileName) == false) { cout << "不存在需要检测词性标注的文件:" << ACheckPosFileName << endl; return -1; } string rightPosFileName = ARightPosFileName; string checkPosFileName = ACheckPosFileName; string mPath = File_GetFilePath(ACheckPosFileName); //3、设置评测生成文件名称 string comparePosFileName = mPath + "PosCompare.txt"; string comparePosFileNameWord = mPath + "PosErrorTotal.txt"; string mEvaluateFileName = mPath + "PosEvaluate.txt"; if (AResultFileNameSuffix != "") { comparePosFileName = File_FileName_AddSuffix(comparePosFileName, AResultFileNameSuffix); comparePosFileNameWord = File_FileName_AddSuffix(comparePosFileNameWord, AResultFileNameSuffix); mEvaluateFileName = File_FileName_AddSuffix(mEvaluateFileName, AResultFileNameSuffix); } fstream rightPosFile, checkPosFile; rightPosFile.open(rightPosFileName.c_str(), ios_base::in); checkPosFile.open(checkPosFileName.c_str(), ios_base::in); FILE * comparePosFile , * comparePosFileWord, * mEvaluateFile; comparePosFile = fopen(comparePosFileName.c_str(), "w"); comparePosFileWord = fopen(comparePosFileNameWord.c_str(), "w"); mEvaluateFile = fopen(mEvaluateFileName.c_str(), "w"); hash_map<string,int,StrHashTrait<string> > mHashWordError; vector<string> vectRightWord, vectCheckWord; string rightPos; string checkPos; int mSumWord = 0; int mErrorWord = 0; const string ct_Separator = " "; int mCompareRowCount = 0; while (( !rightPosFile.eof()) && (!checkPosFile.eof())) { if (getline(rightPosFile, rightPos) == NULL) break; if (getline(checkPosFile, checkPos) == NULL) break; mCompareRowCount ++; // vectRightWord.clear(); String_SeperateToList_WithTrim(rightPos, vectRightWord, ct_Separator); mSumWord += vectRightWord.size(); if (rightPos != checkPos) { fprintf(comparePosFile, "%s\n", rightPos.c_str()); fprintf(comparePosFile, "%s\n", checkPos.c_str()); fprintf(comparePosFile, "\n"); vectCheckWord.clear(); String_SeperateToList_WithTrim(checkPos, vectCheckWord, ct_Separator); for (int k = 0 ; k < vectRightWord.size(); k ++) { string & mRightWordPos = vectRightWord[k]; string & mCheckWordPos = vectCheckWord[k]; if (mRightWordPos != mCheckWordPos) { mErrorWord ++; int mIndex = mRightWordPos.find("/", 0); string mWord = mRightWordPos.substr(0, mIndex); string rightPosTag = mRightWordPos.substr( mIndex + 1 , mRightWordPos.length() - mIndex - 1 ); string errorPosTag = mCheckWordPos.substr( mIndex + 1 , mCheckWordPos.length() - mIndex - 1 ); string key = mWord + "*" + rightPosTag + "*" + errorPosTag; if (mHashWordError.find(key) != mHashWordError.end()) { mHashWordError[key] = mHashWordError[key] + 1; } else { mHashWordError.insert(pair<string, int>(key, 1)); } } } } } hash_map<string,int,StrHashTrait<string> > ::iterator mIter, mHashBegin, mHashEnd; mHashBegin = mHashWordError.begin(); mHashEnd = mHashWordError.end(); for (mIter = mHashBegin ; mIter != mHashEnd; mIter ++) { const string &mKey = mIter -> first; int &mValue = mIter -> second; fprintf(comparePosFileWord, "%s %d\n", mKey.c_str(), mValue); } fprintf(mEvaluateFile, "正确率 = %16.15f\n" , (1 - ((double)mErrorWord / mSumWord))); fprintf(mEvaluateFile, "总词数 = %d\n" , mSumWord); fprintf(mEvaluateFile, "错误标注词数 = %d\n" , mErrorWord); fprintf(mEvaluateFile, "文件行数 = %d\n" , mCompareRowCount); rightPosFile.close(); checkPosFile.close(); fclose(comparePosFile); fclose(comparePosFileWord); fclose(mEvaluateFile); return (1 - ((double)mErrorWord / mSumWord)); }
int PAK_Pack(char *name, char *spath, char *path, char *AddList, int flags) { char fname[MAX_PATH]; pakheader_t header; pakentry_t *entry; int n, offset; FILE *fp, *fp1; totalfiles=totaldirs=0; // create file list & calculate amount of files to be packed while(*AddList) { if(!isDir(AddList)) { files[totalfiles++]=AddList; if(totalfiles==MAX_FILES_IN_PACK) return E_TOO_MANY_FILES; } else { dirs[totaldirs++]=AddList; if(totaldirs==MAX_DIRS) return E_TOO_MANY_FILES; } while(*AddList++); } if(!totalfiles) return E_NO_FILES; // are we adding to existing archive? if(File_Exist(name)) return PAK_Add(name, spath, path, AddList, flags); // prepare header header.magic[0]='P'; header.magic[1]='A'; header.magic[2]='C'; header.magic[3]='K'; header.dirsize=sizeof(pakentry_t)*totalfiles; fp=fopen(name, "wb"); if(!fp) return E_ECREATE; entry=malloc(header.dirsize); if(!entry) {fclose(fp); return E_NO_MEMORY;} memset(entry, 0, header.dirsize); fwrite(&header, sizeof(header), 1, fp); offset=sizeof(header); for(n=0; n<totalfiles; n++) { entry[n].offset=offset; PrepareName(entry[n].filename, spath, files[n], flags&PK_PACK_SAVE_PATHS); strlwr(entry[n].filename); if(!entry[n].filename[0]) continue; if(path) sprintf(fname, "%s%s", path, files[n]); else strcpy(fname, files[n]); fp1=fopen(fname, "rb"); if(!fp1) continue;//{fclose(fp); free(entry); return E_EOPEN;} entry[n].size=cpy(fp, fp1, fname); fclose(fp1); // move to archive if(flags&PK_PACK_MOVE_FILES) remove(fname); offset+=entry[n].size; } header.diroffset=offset; fwrite(entry, header.dirsize, 1, fp); fseek(fp, 0, SEEK_SET); fwrite(&header, sizeof(header), 1, fp); fclose(fp); // delete all dirs if(flags&PK_PACK_MOVE_FILES) { for(n=totaldirs-1; n>=0; n--) _rmdir(dirs[n]); } return 0; }
T_BOOL anyka_spi_update_self(T_BOOL DelUpdateFlag) { //T_U32 *pFilePosInfo = AK_NULL; //T_U32 ClusterNum = 0; //T_U32 SecPerClus = 0; T_SPIBURNFUNC spi_BurnFunc; T_U32* pdateGetInfo; T_U32 file = AK_NULL; const T_U16 path[]={'A',':','/','u','p','d','a','t','e','.','U','P','D',0}; T_SFLASH_PARAM *pParam; pParam = (T_SFLASH_PARAM*)(0x00800040); AK_DEBUG_OUTPUT("test_spi_update_self start\n"); file = File_OpenUnicode(AK_NULL, path, FILE_MODE_READ); if (!File_Exist(file)) { /* Whatever mode you open the file, it fails when it doesn't exist. */ AK_DEBUG_OUTPUT("test_spi_update_self: open upd file error\n"); File_Close(file); return AK_FALSE; } else { #ifdef SUPPORT_VOICE_TIP Voice_PlayTip(eBTPLY_SOUND_TYPE_UPDATE, AK_NULL); Voice_WaitTip(); #endif } //gpio_set_pin_dir(GPIO_POWER_CTRL, 1); //gpio_set_pin_level(GPIO_POWER_CTRL, 1); if (AK_NULL == g_pSpiStack) { g_SpiStackPtr = 0; g_pSpiStack = (T_U8 *)Fwl_DMAMalloc(SPI_UPDATE_SELF_BUF_SIZE);//徐申实现 平台的molloc if(g_pSpiStack==AK_NULL) { akerror("test_spi_update_self: malloc fail",SPI_UPDATE_SELF_BUF_SIZE,1); return AK_FALSE; } } filelen = File_GetLength(file, AK_NULL); pdateGetInfo = File_GetfileclusterInfo_ToUpdate(file,&ClusterNum, &SecPerClus); /*因为簇链已经得到,可以删除,文件删除不会干掉真正的内容的*/ #if 1 if(DelUpdateFlag && (!Fwl_FileDeleteHandle(file))) { akerror("test_spi_update_self: File_DeleteFile fail",0,1); Fwl_DMAFree(g_pSpiStack); File_Close(file); return AK_FALSE; } #endif File_Close(file); if (AK_NULL == pdateGetInfo) { //fwl_closefile关闭文件句柄 //File_Close(file); akerror("test_spi_update_self: get pdateGetInfo fail",0,1); Fwl_DMAFree(g_pSpiStack); return AK_FALSE; } pFilePosInfo = pdateGetInfo; spi_BurnFunc.RamAlloc = SPI_RamAlloc; spi_BurnFunc.RamFree = SPI_RamFree; spi_BurnFunc.MemSet = ak_memset; spi_BurnFunc.MemCpy = ak_memcpy; spi_BurnFunc.MemCmp = ak_memcmp; spi_BurnFunc.Printf = AkDebugOutput;//AK_DEBUG_OUTPUT;// spi_BurnFunc.fSeek =upd_fileseek;///Fwl_FileSeek;// spi_BurnFunc.fRead =upd_fileread;///Fwl_FileRead;// { AK_DEBUG_OUTPUT("clock: 0x%x \r\n", pParam->clock); AK_DEBUG_OUTPUT("erase_size: 0x%x \r\n", pParam->erase_size); AK_DEBUG_OUTPUT("flag: 0x%x \r\n", pParam->flag); AK_DEBUG_OUTPUT("id: 0x%04x \r\n", pParam->id); AK_DEBUG_OUTPUT("page_size: 0x%x \r\n", pParam->page_size); AK_DEBUG_OUTPUT("program_size: 0x%x \r\n", pParam->program_size); AK_DEBUG_OUTPUT("protect_mask: 0x%x \r\n", pParam->protect_mask); AK_DEBUG_OUTPUT("total_size: 0x%x \r\n", pParam->total_size); } if (!UnpacketSpiFileInit(&spi_BurnFunc, file, pParam)) { //fwl_closefile关闭文件句柄 akerror("test_spi_update_self: UnpacketSpiFileInit fail",0,1); Fwl_DMAFree(g_pSpiStack); return AK_FALSE; } if (!UnpacketSpiBinFile(file)) { //fwl_closefile关闭文件句柄 // File_Close(file); akerror("UnpacketSpiFileInit: UnpacketSpiBinFile fail",0,1); Fwl_DMAFree(g_pSpiStack); return AK_FALSE; } //后面的是重新读取数据比较是否正确, 需求很大的内存8k,所以不比较 if (!UnpacketSpiBootFile(file, AK_TRUE)) { //fwl_closefile关闭文件句柄 // File_Close(file); akerror("UnpacketSpiFileInit: UnpacketSpiBootFile fail",0,1); Fwl_DMAFree(g_pSpiStack); return AK_FALSE; } //不需要释放了,重新启动会重新初始化内存的 { akerror("UnpacketSpiFileInit: SPI update successed!",0,1); } /*测试中sys_reset回进入massboot,所以目前进入sys_reset();*/ Fwl_SysReboot(); while(1); return AK_TRUE; }