int main (int argc, char **argv) { int32 Status; EEFS_DirectoryDescriptor_t *DirDescriptor = NULL; EEFS_DirectoryEntry_t *DirEntry = NULL; EEFS_Stat_t StatBuffer; int32 eefs_fd; int host_fd; int total_used_space; int total_free_space; /* ** Process the command line options */ SetCommandLineOptionsDefaults(&CommandLineOptions); ProcessCommandLineOptions(argc, argv, &CommandLineOptions); /* ** Open the device ( BDM or image file ) */ eefstool_open_device(); /* ** Init the EEFS */ /* ** Mount the EEPROM disk volumes */ Status = EEFS_InitFS("/EEDEV1", CommandLineOptions.EEFSMemoryAddress); if ( Status == 0 ) { Status = EEFS_Mount("/EEDEV1",eefs_mountpoint); if ( Status != 0 ) { printf("Error: Failed to mount EEPROM File System\n"); } } else { printf("Error: Failed to initialize EEPROM FS\n"); } /* ** Process the command */ if ( CommandLineOptions.DirectoryListingCommand == TRUE ) { /* ** Get a directory of the EEFS */ DirDescriptor = EEFS_OpenDir(eefs_mountpoint); if ( DirDescriptor != NULL ) { DirEntry = NULL; printf("--> EEFS Directory:\n"); printf("%32s %10s\n","Filename","Size"); printf("------------------------------------------------------\n"); while ( (DirEntry = EEFS_ReadDir(DirDescriptor)) != NULL ) { if ( DirEntry->InUse != 0 ) { printf("%32s %10d\n",DirEntry->Filename,(int)DirEntry->MaxFileSize); } } printf("------------------------------------------------------\n"); Status = EEFS_CloseDir(DirDescriptor); } } if ( CommandLineOptions.EepromUsageCommand == TRUE ) { /* ** Dump the EEPROM usage stats for the EEFS */ total_used_space = 0; total_free_space = 0; DirDescriptor = EEFS_OpenDir(eefs_mountpoint); if ( DirDescriptor != NULL ) { DirEntry = NULL; printf("--> EEFS Usage Stats:\n"); printf("%32s %10s %10s\n","Filename","Size", "Max Size"); printf("------------------------------------------------------\n"); while ( (DirEntry = EEFS_ReadDir(DirDescriptor)) != NULL ) { if ( DirEntry->InUse != 0 ) { strcpy(eefs_filename, eefs_mountpoint); strcat(eefs_filename,"/"); strcat(eefs_filename,DirEntry->Filename); Status = EEFS_Stat(eefs_filename, &StatBuffer); if ( Status == 0 ) { printf("%32s %10d %10d\n",DirEntry->Filename, (int)StatBuffer.FileSize, (int)DirEntry->MaxFileSize); total_used_space = total_used_space + StatBuffer.FileSize; total_free_space = total_free_space + ( DirEntry->MaxFileSize - StatBuffer.FileSize); } else { printf("Error: Cannot get Stat buffer for file: %s\n",eefs_filename); } } } printf("------------------------------------------------------\n"); printf("Total Used space = %d bytes.\n",total_used_space); printf("Total Free space = %d bytes.\n",total_free_space); printf("Total Space = %d bytes.\n",total_used_space + total_free_space); Status = EEFS_CloseDir(DirDescriptor); } } else if ( CommandLineOptions.CopyFromCommand == TRUE ) //读取EEPROM复制到文件系统中 { //打开一个文件只写 host_fd = open(CommandLineOptions.Filename2, O_CREAT | O_WRONLY, S_IRWXU ); if ( host_fd < 0 ) { printf("Error opening host file: %s\n",CommandLineOptions.Filename2); } else { strcpy(eefs_filename, eefs_mountpoint); strcat(eefs_filename,"/"); // strcat(eefs_filename,CommandLineOptions.Filename1); eefs_fd = EEFS_Open(eefs_filename, 0);//打开EEFS 文件系统 if ( eefs_fd < 0 ) { printf("Error opening EEFS file: %s\n",CommandLineOptions.Filename1); close(host_fd); } else { int32 DataRead; int DataWritten; boolean DataToRead; char buffer[512]; /* ** Copy the file */ printf("Copying: EEPROM File System: %s, to the host: %s\n", CommandLineOptions.Filename1, CommandLineOptions.Filename2); DataToRead = TRUE; while ( DataToRead == TRUE ) { DataRead = EEFS_Read(eefs_fd, &buffer[0], 512); //读取512字节到BUF中 if ( DataRead == 0 ) { DataToRead = FALSE; } else { DataWritten = write(host_fd, &buffer[0],DataRead); //将EEPROM内的数据写入文件中 if ( DataWritten != DataRead ) { printf("Warning: Amount of data written != Data Read\n"); } } } /* End while */ EEFS_Close(eefs_fd);//关闭EE文件系统 close(host_fd); printf("Copy completed\n"); } } } else if ( CommandLineOptions.CopyToCommand == TRUE ) //从文件系统复制到EEPROM中 { host_fd = open(CommandLineOptions.Filename1, O_RDONLY, S_IRWXU ); if ( host_fd < 0 ) { printf("Error opening host file: %s\n",CommandLineOptions.Filename1); } else { strcpy(eefs_filename, eefs_mountpoint); strcat(eefs_filename,"/"); strcat(eefs_filename,CommandLineOptions.Filename2); //源文件/命令行文件--格式 eefs_fd = EEFS_Creat(eefs_filename, 0); //创建一个名为文件eefs_filename变量包含的 if ( eefs_fd < 0 ) { printf("Error calling EEFS_Creat on EEFS file: %s\n",CommandLineOptions.Filename2); close(host_fd); } else { int32 DataRead; int DataWritten; boolean DataToRead; char buffer[512]; /* ** Copy the file */ printf("Copying: From the host file %s, to the EEPROM File System file: %s.\n", CommandLineOptions.Filename1, CommandLineOptions.Filename2); DataToRead = TRUE; while ( DataToRead == TRUE ) { DataRead = read(host_fd, &buffer[0], 512); if ( DataRead == 0 ) { DataToRead = FALSE; } else { DataWritten = EEFS_Write(eefs_fd, &buffer[0],DataRead); if ( DataWritten != DataRead ) { printf("Warning: Amount of data written != Data Read\n"); } } } /* End while */ EEFS_Close(eefs_fd); close(host_fd); printf("\nCopy completed\n"); } } } else if ( CommandLineOptions.DeleteCommand == TRUE ) { printf("Deleting %s from the EEPROM File system\n", CommandLineOptions.Filename1); printf("Done\n"); } else if ( CommandLineOptions.RenameCommand == TRUE ) { printf("Rename a file on the EEPROM file system from: %s, to %s\n", CommandLineOptions.Filename1, CommandLineOptions.Filename2); } /* ** Close the device ( BDM or image file ) */ eefstool_close_device(); return 0; }
int CSModuleLoaded(WPARAM wParam, LPARAM lParam) { protoList = (OBJLIST<PROTOCOLSETTINGEX>*)&startupSettings; InitProfileModule(); HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccChanged); HookEvent(ME_OPT_INITIALISE, OptionsInit); /* shutdown hook for normal shutdown */ HookEvent(ME_SYSTEM_OKTOEXIT, OnOkToExit); HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown); /* message window for poweroff */ hMessageWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); SetWindowLongPtr(hMessageWindow, GWLP_WNDPROC, (LONG_PTR)MessageWndProc); GetProfile(-1, startupSettings); // override with cmdl ProcessCommandLineOptions(startupSettings); if (startupSettings.getCount() == 0) return 0;// no protocols are loaded SetLastStatusMessages(startupSettings); showDialogOnStartup = (showDialogOnStartup || db_get_b(NULL, MODULENAME, SETTING_SHOWDIALOG, 0)); // dial if (showDialogOnStartup || db_get_b(NULL, MODULENAME, SETTING_SETPROFILE, 1)) if (db_get_b(NULL, MODULENAME, SETTING_AUTODIAL, 0)) InternetAutodial(0, NULL); // set the status! if (showDialogOnStartup || db_get_b(NULL, MODULENAME, SETTING_SHOWDIALOG, 0)) CallService(MS_CS_SHOWCONFIRMDLGEX, (WPARAM)&startupSettings, db_get_dw(NULL, MODULENAME, SETTING_DLGTIMEOUT, 5)); else if (db_get_b(NULL, MODULENAME, SETTING_SETPROFILE, 1)) { // set hooks for override if (db_get_b(NULL, MODULENAME, SETTING_OVERRIDE, 1)) { hProtoAckHook = HookEvent(ME_PROTO_ACK, ProcessProtoAck); hCSStatusChangeHook = HookEvent(ME_CS_STATUSCHANGEEX, CSStatusChangeEx); hStatusChangeHook = HookEvent(ME_CLIST_STATUSMODECHANGE, StatusChange); } setStatusTimerId = SetTimer(NULL, 0, db_get_dw(NULL, MODULENAME, SETTING_SETPROFILEDELAY, 500), SetStatusTimed); } // win size and location if (db_get_b(NULL, MODULENAME, SETTING_SETWINLOCATION, 0) || db_get_b(NULL, MODULENAME, SETTING_SETWINSIZE, 0)) { HWND hClist = pcli->hwndContactList; // store in db if (db_get_b(NULL, MODULENAME, SETTING_SETWINLOCATION, 0)) { db_set_dw(NULL, MODULE_CLIST, SETTING_XPOS, db_get_dw(NULL, MODULENAME, SETTING_XPOS, 0)); db_set_dw(NULL, MODULE_CLIST, SETTING_YPOS, db_get_dw(NULL, MODULENAME, SETTING_YPOS, 0)); } if (db_get_b(NULL, MODULENAME, SETTING_SETWINSIZE, 0)) { db_set_dw(NULL, MODULE_CLIST, SETTING_WIDTH, db_get_dw(NULL, MODULENAME, SETTING_WIDTH, 0)); if (!db_get_b(NULL, MODULE_CLUI, SETTING_AUTOSIZE, 0)) db_set_dw(NULL, MODULE_CLIST, SETTING_HEIGHT, db_get_dw(NULL, MODULENAME, SETTING_HEIGHT, 0)); } WINDOWPLACEMENT wndpl = { sizeof(wndpl) }; if (GetWindowPlacement(hClist, &wndpl)) { if (wndpl.showCmd == SW_SHOWNORMAL && !CallService(MS_CLIST_DOCKINGISDOCKED, 0, 0)) { RECT rc; if (GetWindowRect(hClist, &rc)) { int x = rc.left; int y = rc.top; int width = rc.right - rc.left; int height = rc.bottom - rc.top; if (db_get_b(NULL, MODULENAME, SETTING_SETWINLOCATION, 0)) { x = db_get_dw(NULL, MODULENAME, SETTING_XPOS, x); y = db_get_dw(NULL, MODULENAME, SETTING_YPOS, y); } if (db_get_b(NULL, MODULENAME, SETTING_SETWINSIZE, 0)) { width = db_get_dw(NULL, MODULENAME, SETTING_WIDTH, width); if (!db_get_b(NULL, MODULE_CLUI, SETTING_AUTOSIZE, 0)) height = db_get_dw(NULL, MODULENAME, SETTING_HEIGHT, height); } MoveWindow(hClist, x, y, width, height, TRUE); } } } } return 0; }