bool shObject::systemRunPOST (void) { if (mEnhancement >= kGoodSys) { if (!isBugginessKnown ()) { if (isBuggy ()) I->p ("Warning! POST detected hardware malfunction."); else if (isOptimized ()) I->p ("POST running... high performance settings active."); else I->p ("POST running... all tests passed."); setBugginessKnown (); if (isBuggy ()) return I->yn ("Cancel execution?"); } } return true; }
int shObject::execTime (void) { /* Optimized computers execute programs faster. */ return isOptimized () ? FULLTURN : LONGTURN; }
int _XResourcePack::makeResourcePack(int packMode) { FILE *fpTemp = NULL; FILE *fp = NULL; //打开文件列表 if((fp = fopen(FILE_LIST_TEXT_NAME,"r")) == NULL) { #ifdef DEBUG_MODE printf("File list file open error!\n"); #endif return -1; } //完成文件列表的信息 m_fileSum = 0; //实际操作的文件数量 char fileNameTemp[MAX_FILE_NAME_LENGTH]; char fileNameTemp1[MAX_FILE_NAME_LENGTH]; _XBool flag = XTrue; for(int i = 0;i < MAX_FILE_SUM;++ i) { while(1) { if(feof(fp)) { flag = XFalse; break; } fileNameTemp[0] = '\0'; fscanf(fp,"%s",fileNameTemp); if(fileNameTemp[0] == '\0') continue; int tempLen = getStringLength(fileNameTemp); if(tempLen < 4) continue; if(packMode == 0) {//不加密的文件 if(fileNameTemp[tempLen - 4] != '.') continue; strcpy(fileNameTemp1,fileNameTemp); //tempLen = strlen(fileNameTemp1); for(int j = 0;j < tempLen;++j) { if(fileNameTemp1[j] == '/' || fileNameTemp1[j] == '\\') { fileNameTemp1[j] = '\0'; } } if(fileNameCompare(fileNameTemp1,"normalResource") == 0) continue; //只有normalResource目录下面的文件才会经过这个处理 }else { if(fileNameCompare(fileNameTemp,"ResourcePack.exe") == 1) continue; //去掉可执行文件自身 if(fileNameCompare(fileNameTemp,"ResourceFileList.txt") == 1) continue; //去掉文件列表文档 if(fileNameCompare(fileNameTemp,"Resource.dat") == 1) continue; //去掉资源包文件 if(fileNameTemp[tempLen - 4] != '.') continue; //这个可以不必要如此处理,这一行的目的是为了去掉文件夹,保证选取的都是文件 //下面去掉资源优化产生的几个临时文件 if(fileNameCompare(fileNameTemp,PNG_FILE_LIST_NAME) == 1) continue; //去掉资源优化中间文件 if(fileNameCompare(fileNameTemp,"!!BasePath.png") == 1) continue; //去掉资源优化中间文件 if(fileNameCompare(fileNameTemp,"logBook.txt") == 1) continue; //去掉资源优化中间文件 //DLL文件不需要打包 if(fileNameTemp[tempLen - 4] == '.' && (fileNameTemp[tempLen - 3] == 'D' || fileNameTemp[tempLen - 3] == 'd') && (fileNameTemp[tempLen - 2] == 'L' || fileNameTemp[tempLen - 2] == 'l') && (fileNameTemp[tempLen - 1] == 'L' || fileNameTemp[tempLen - 1] == 'l')) continue; //取消已经处理过的文件 if(isOptimized(fileNameTemp) == 1) continue; strcpy(fileNameTemp1,fileNameTemp); //tempLen = strlen(fileNameTemp1); for(int j = 0;j < tempLen;++j) { if(fileNameTemp1[j] == '/' || fileNameTemp1[j] == '\\') { fileNameTemp1[j] = '\0'; } } if(fileNameCompare(fileNameTemp1,"normalResource") == 1) continue; //normalResource目录下的文件不会经过这个处理 } break; } if(!flag) break; memset(m_fileInfo[i].fileName,0,sizeof(m_fileInfo[i].fileName)); //初始化内存空间(避免UMR错误),实际上并没有必要 memcpy(m_fileInfo[i].fileName,fileNameTemp,sizeof(fileNameTemp)); // printf("%s\n",m_fileInfo[i].fileName); if((fpTemp = fopen(m_fileInfo[i].fileName,"r")) == NULL) { #ifdef DEBUG_MODE printf("File list file text error!\n"); #endif return -1; } fseek(fpTemp,0,SEEK_END); m_fileInfo[i].fileLength = ftell(fpTemp); //获取文件的长度 fseek(fpTemp,0,SEEK_SET); fclose(fpTemp); m_fileSum ++; } fclose(fp); if(flag) { #ifdef DEBUG_MODE printf("Need packed files is more than %d.Pack filed!\n",MAX_FILE_SUM); #endif return 0; } //开始打包文件 if(packMode == 0) {//不加密的文件放在资源文件的头部,所以需要以全新写的方式打开文件 if((fp = fopen(m_outFileName,"wb")) == NULL) { if((fp = fopen(m_outFileName,"ab")) == NULL) { #ifdef DEBUG_MODE printf("File list file open error!\n"); #endif return -1; } } //写入包头长度 m_headLength = m_fileSum * sizeof(_XResourceFileStruct); fwrite(&m_headLength,sizeof(m_headLength),1,fp); //4bytes //写入包头加上文件的总长度 for(int i = 0;i < m_fileSum;++ i) { m_headLength += m_fileInfo[i].fileLength; } fwrite(&m_headLength,sizeof(m_headLength),1,fp); //4bytes //写入包头内容 for(int i = 0;i < m_fileSum;++ i) { if(i > 0) { m_fileInfo[i].filePosition = m_fileInfo[i-1].filePosition + m_fileInfo[i-1].fileLength; }else { m_fileInfo[i].filePosition = sizeof(m_headLength) + sizeof(m_headLength) + m_fileSum * sizeof(_XResourceFileStruct); } fwrite(m_fileInfo[i].fileName,sizeof(m_fileInfo[i].fileName),1,fp); fwrite(&(m_fileInfo[i].fileLength),sizeof(m_fileInfo[i].fileLength),1,fp); fwrite(&(m_fileInfo[i].filePosition),sizeof(m_fileInfo[i].filePosition),1,fp); //printf("%s,%ld,%ld,%ld\n",m_fileInfo[i].fileName,m_fileInfo[i].fileLength,m_fileInfo[i].filePosition,ftell(fp)); #ifdef DEBUG_MODE printf("File %s packed.\n",m_fileInfo[i].fileName); #endif } //写入文件内容 unsigned char tempFileData[2048]; int readLength = 0; for(int i = 0;i < m_fileSum;++ i) { if((fpTemp = fopen(m_fileInfo[i].fileName,"rb")) == NULL) { #ifdef DEBUG_MODE printf("Resource file read error!\n"); #endif return -1; } readLength = 0; //printf"%d\n",ftell(fp)); while(1) {//复制文件 if(m_fileInfo[i].fileLength - readLength > 2048) { fread(tempFileData,2048,1,fpTemp); fwrite(tempFileData,2048,1,fp); readLength += 2048; }else { fread(tempFileData,m_fileInfo[i].fileLength - readLength,1,fpTemp); fwrite(tempFileData,m_fileInfo[i].fileLength - readLength,1,fp); fclose(fpTemp); break; } } } //结束 fclose(fp); }else {//加密的文件,放在文件尾部,所以需要以追加的方式打开文件 if((fp = fopen(m_outFileName,"ab")) == NULL) { #ifdef DEBUG_MODE printf("File list file open error!\n"); #endif return -1; } //写入文件说明 char temp[] = FILE_CODE; fwrite(temp,sizeof(temp),1,fp); //23bytes //printf("%d\n",ftell(fp)); //写入包头长度 m_headLength = LOCK_CODE_LENGTH + m_fileSum * sizeof(_XResourceFileStruct); fwrite(&m_headLength,sizeof(m_headLength),1,fp); //4bytes //printf"%d\n",ftell(fp)); //写入32bytes的随机码 for(int i = 0;i < LOCK_CODE_LENGTH;++ i) { tempCode[i] = rand()%256; } fwrite(tempCode,LOCK_CODE_LENGTH,1,fp); //32bytes getlockKey(); //计算掩码 //printf"%d,%d\n",ftell(fp),m_headLength); int tempFilePosition = sizeof(FILE_CODE) + sizeof(long) + LOCK_CODE_LENGTH; //写入包头内容 for(int i = 0;i < m_fileSum;++ i) { if(i > 0) { // m_fileInfo[i].filePosition = sizeof(FILE_CODE) + sizeof(long) + m_headLength + m_fileInfo[i-1].fileLength; m_fileInfo[i].filePosition = m_fileInfo[i-1].filePosition + m_fileInfo[i-1].fileLength; }else { m_fileInfo[i].filePosition = sizeof(FILE_CODE) + sizeof(long) + m_headLength; } lockOrUnlockProc((unsigned char *)m_fileInfo[i].fileName,tempFilePosition,sizeof(m_fileInfo[i].fileName)); //加密 fwrite(m_fileInfo[i].fileName,sizeof(m_fileInfo[i].fileName),1,fp); lockOrUnlockProc((unsigned char *)m_fileInfo[i].fileName,tempFilePosition,sizeof(m_fileInfo[i].fileName)); //还原 tempFilePosition += sizeof(m_fileInfo[i].fileName); lockOrUnlockProc((unsigned char *)&(m_fileInfo[i].fileLength),tempFilePosition,sizeof(m_fileInfo[i].fileLength)); //加密 fwrite(&(m_fileInfo[i].fileLength),sizeof(m_fileInfo[i].fileLength),1,fp); lockOrUnlockProc((unsigned char *)&(m_fileInfo[i].fileLength),tempFilePosition,sizeof(m_fileInfo[i].fileLength)); //还原 tempFilePosition += sizeof(m_fileInfo[i].fileLength); lockOrUnlockProc((unsigned char *)&(m_fileInfo[i].filePosition),tempFilePosition,sizeof(m_fileInfo[i].filePosition)); //加密 fwrite(&(m_fileInfo[i].filePosition),sizeof(m_fileInfo[i].filePosition),1,fp); lockOrUnlockProc((unsigned char *)&(m_fileInfo[i].filePosition),tempFilePosition,sizeof(m_fileInfo[i].filePosition)); //还原 tempFilePosition += sizeof(m_fileInfo[i].filePosition); //printf("%s,%ld,%ld,%ld\n",m_fileInfo[i].fileName,m_fileInfo[i].fileLength,m_fileInfo[i].filePosition,ftell(fp)); #ifdef DEBUG_MODE printf("File %s packed.\n",m_fileInfo[i].fileName); #endif } //写入文件内容 unsigned char tempFileData[2048]; int readLength = 0; for(int i = 0;i < m_fileSum;++ i) { if((fpTemp = fopen(m_fileInfo[i].fileName,"rb")) == NULL) { #ifdef DEBUG_MODE printf("Resource file read error!\n"); #endif return -1; } readLength = 0; //printf"%d\n",ftell(fp)); while(1) {//复制文件 if(m_fileInfo[i].fileLength - readLength > 2048) { fread(tempFileData,2048,1,fpTemp); //lockOrUnlockProc(tempFileData,ftell(fp),2048); lockOrUnlockProc(tempFileData,tempFilePosition,2048); tempFilePosition += 2048; fwrite(tempFileData,2048,1,fp); readLength += 2048; }else { fread(tempFileData,m_fileInfo[i].fileLength - readLength,1,fpTemp); //lockOrUnlockProc(tempFileData,ftell(fp),m_fileInfo[i].fileLength - readLength); lockOrUnlockProc(tempFileData,tempFilePosition,m_fileInfo[i].fileLength - readLength); tempFilePosition += m_fileInfo[i].fileLength - readLength; fwrite(tempFileData,m_fileInfo[i].fileLength - readLength,1,fp); fclose(fpTemp); break; } } } //结束 fclose(fp); writeCheckData(); } #ifdef DEBUG_MODE if(packMode == 0) printf("Normal resource packed finished,%d file packed!\n",m_fileSum); else printf("Other resource packed finished,%d file packed!\n",m_fileSum); #endif return 1; }