📄 data_file.cpp
字号:
#include "runner.h"
#include "time.h"
int compare( const void *arg1, const void *arg2 )
{
/* Compare all of both strings: */
return _stricmp( * ( char** ) arg1, * ( char** ) arg2 );
}
SINT8 GetDirFileName(SINT8 ** file_list , SINT8 *p_dir_name , SINT8 load_mode)
{
int i;
for(i=0;i<MAX_FILE_IN_DIR;i++) file_list[i]=NULL;
_finddata_t filestruct;
int p = 0;
int fn = 0;
SINT8 dir_name[MAX_PATHX];
strcpy(dir_name , p_dir_name);
strcat(dir_name , "/*.*");
SINT32 hnd = _findfirst(dir_name,&filestruct);
if((hnd==-1))
{
printf("no file found in dir [%s]\n",dir_name);
return 0;
}
else
{
if(!(filestruct.attrib & _A_SUBDIR))
{
SINT8 *str;GetMemory(str , CHAR , strlen(filestruct.name) + 1);
strcpy(str , filestruct.name);
file_list[fn] = str;
//printf(":<%s>\n",file_list[fn]);
fn++;
}
}
while(!_findnext(hnd,&filestruct))
{
if(!(filestruct.attrib & _A_SUBDIR))
{
SINT8 *str;GetMemory(str , CHAR , strlen(filestruct.name) + 1);
strcpy(str , filestruct.name);
file_list[fn] = str;
//printf(":<%s>\n",file_list[fn]);
fn++;
if(fn==MAX_FILE_IN_DIR) break;
}
}
_findclose(hnd);
if(fn==0) return 0;
SINT8 **argvx = (SINT8**)file_list;
if(fn>1)
{
qsort( (void *)argvx , (size_t) fn , sizeof( SINT8 *), compare );
}
return 1;
}
SINT8 GetExeBuildTime(SINT8 *time_str)
{
SINT8 exe_name[MAX_PATHX];
GetModuleFileName(NULL , exe_name , MAX_PATHX);
_finddata_t filestruct;
SINT32 hnd = _findfirst(exe_name , &filestruct);
if((hnd==-1))
{
Out("ERR : No File <%s> Found(GetExeBuildTime()\n" , exe_name);
return 0;
}
struct tm *temp_time;
temp_time = gmtime(&(filestruct.time_write));
SINT8 month[4];
SINT8 day[4];
SINT8 hour[4];
SINT8 min[4];
if(temp_time->tm_mon<10) sprintf(month , "0%d" ,temp_time->tm_mon + 1);
else sprintf(month , "%d" ,temp_time->tm_mon + 1);
if(temp_time->tm_mday<10) sprintf(day , "0%d" ,temp_time->tm_mday);
else sprintf(day , "%d" ,temp_time->tm_mday);
if(temp_time->tm_hour<2) sprintf(hour , "0%d" ,temp_time->tm_hour + 8);
else sprintf(hour , "%d" ,temp_time->tm_hour + 8);
if(temp_time->tm_min<10) sprintf(min , "0%d" ,temp_time->tm_min);
else sprintf(min , "%d" ,temp_time->tm_min);
sprintf(time_str , "%s/%s/%s:%s %d" , month , day , hour , min , temp_time->tm_year + 1900);
return 1;
}
UINT32 GetFileSize(SINT8 *file_name)
{
FILE *fp = fopen(file_name , "rb");
if(fp==NULL)
{
Out("ERR : file [%s] is not exist(GetFileSize())\n" , file_name);
return 0;
}
fseek(fp , 0 , SEEK_END);
UINT32 size = ftell(fp);
fclose(fp);
return size;
}
VOID DataToTextFile(LPBYTE pbData , int iWidth , int iHeight , TCHAR *strFileName)
{
FILE *fp = fopen(strFileName , "wt");
LPBYTE pbCurData = pbData;
for(int y = 0 ; y < iHeight ; y++)
{
for(int x = 0 ; x < iWidth ; x++)
{
if(*(pbCurData + x)==1)
{
fprintf(fp , "%s" , "*");
}
else
{
fprintf(fp , "%s" , ".");
}
}
pbCurData+=iWidth;
fprintf(fp , "\n");
}
fclose(fp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -