void PMenu::renameLnkFiles(QDir base_dir) { PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { if( item->old_name.isEmpty() ) continue; if( item->entry_type == submenu ) { if( item->real_name != item->old_name ) if( base_dir.exists( item->old_name ) ) { base_dir.rename( item->old_name, item->real_name ); item->old_name = item->real_name; } QDir sub_dir(base_dir); if( !sub_dir.cd(item->old_name) ) continue; item->sub_menu->renameLnkFiles( sub_dir ); } if( item->real_name == item->old_name || item->entry_type == separator ) continue; if( base_dir.exists( item->old_name ) ) { base_dir.rename( item->old_name, item->real_name ); item->old_name = item->real_name; } } }
void PMenu::copyLnkFiles(QDir base_dir) { PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { if( item->entry_type == submenu ) { QDir sub_dir(base_dir); if( item->old_name.isEmpty() ) { if( item->real_name.isEmpty() ) item->real_name = item->text_name; base_dir.mkdir(item->real_name); if( !sub_dir.cd(item->real_name) ) continue; } else { if( !base_dir.exists( item->old_name ) ) { base_dir.mkdir(item->old_name); if( base_dir.exists( item->dir_path + '/' + item->old_name + "/.directory") ) copyFiles( item->dir_path + '/' + item->old_name + "/.directory", base_dir.absPath() + '/' + item->old_name + "/.directory" ); } if( !sub_dir.cd(item->old_name) ) continue; } item->sub_menu->copyLnkFiles( sub_dir ); } } for( item = list.first(); item != 0; item = list.next() ) { if( item->entry_type == separator || item->old_name.isEmpty() ) continue; if( item->entry_type != submenu ) { if( base_dir.exists( item->old_name ) ) continue; else { if( base_dir.exists( item->dir_path + '/' + item->old_name ) ) copyFiles( item->dir_path + '/' + item->old_name, base_dir.absPath() + '/' + item->old_name ); } } } }
void FileFixture::recursiveRmDir(QDir dir) { TasLogger::logger()->debug("FileFixture::recursiveRmDir: " + dir.absolutePath()); //iterate all files and subfolder, then delete this dir QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries); for(int n=0;n<list.size();n++){ QFileInfo info = list.at(n); TasLogger::logger()->debug(" > " + info.absoluteFilePath()); if(info.isDir()){ QDir sub_dir(info.absoluteFilePath()); recursiveRmDir(sub_dir); dir.rmdir(sub_dir.absolutePath()); } else if(info.isFile()) { QFile file; file.remove(info.absoluteFilePath()); } } }
int FtpConfig( char test, char* filename ) { char cmd[128]; FILE* fp = NULL; struct stat stStat; int iRet; int flag = 0; if ( bparam.stFtpParam.szFtpSvr[0] == 0x00 ) { return -1; } if ( bparam.stFtpParam.szFtpUser[0] == 0x00 ) { return -1; } if ( bparam.stFtpParam.szFtpPwd[0] == 0x00 ) { return -1; } fp = fopen( "/tmp/ftpupdate1.sh", "wb" ); if ( fp == NULL ) { printf( "ftp config failed\n" ); return -1; } memset( cmd, 0x00, 128 ); sprintf( cmd, "/system/system/bin/ftp -n<<!\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "open %s %d\n", bparam.stFtpParam.szFtpSvr, bparam.stFtpParam.nFtpPort ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "user %s %s\n", bparam.stFtpParam.szFtpUser, bparam.stFtpParam.szFtpPwd ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "binary\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); if ( bparam.stFtpParam.byMode == 1 ) //passive { memset( cmd, 0x00, 128 ); sprintf( cmd, "pass\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); } #ifdef CUSTOM_DIR char sub_temp[ 128 ]; memset(sub_temp, 0, 128); //strcpy(sub_temp, bparam.stFtpParam.szFtpDir); sprintf(sub_temp, "%s/%s", bparam.stFtpParam.szFtpDir,bparam.stIEBaseParam.dwDeviceID); flag = sub_dir(fp,sub_temp); if(flag){ memset( cmd, 0x00, 128 ); sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir ); fwrite( cmd, 1, strlen( cmd ), fp ); } #else memset( cmd, 0x00, 128 ); sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir ); fwrite( cmd, 1, strlen( cmd ), fp ); #endif memset( cmd, 0x00, 128 ); sprintf( cmd, "lcd /tmp\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); if ( test == 0x01 ) { FtpFileTest(); memset( cmd, 0x00, 128 ); sprintf( cmd, "put ftptest.txt\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); } else { char filename1[128]; memset( filename1, 0x00, 128 ); memcpy( filename1, filename + 5, strlen( filename ) - 5 ); memset( cmd, 0x00, 128 ); sprintf( cmd, "put %s\n", filename1 ); fwrite( cmd, 1, strlen( cmd ), fp ); } memset( cmd, 0x00, 128 ); sprintf( cmd, "close\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "bye\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "!\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); fclose( fp ); iRet = access( "/tmp/ftpupdate1.sh", X_OK ); if ( iRet ) { DoSystem( "chmod a+x /tmp/ftpupdate1.sh" ); } return 0; }
int FtpConfigAlarm( char test, char* capfilename, char* filename ) { char cmd[128]; FILE* fp = NULL; struct stat stStat; int iRet; int flag = 0; if ( bparam.stFtpParam.szFtpSvr[0] == 0x00 ) { return -1; } if ( bparam.stFtpParam.szFtpUser[0] == 0x00 ) { return -1; } if ( bparam.stFtpParam.szFtpPwd[0] == 0x00 ) { return -1; } fp = fopen( "/tmp/ftpupdate.sh", "wb" ); if ( fp == NULL ) { printf( "ftp config failed\n" ); return -1; } memset( cmd, 0x00, 128 ); sprintf( cmd, "/system/system/bin/ftp -n<<!\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "open %s %d\n", bparam.stFtpParam.szFtpSvr, bparam.stFtpParam.nFtpPort ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "user %s %s\n", bparam.stFtpParam.szFtpUser, bparam.stFtpParam.szFtpPwd ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "binary\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); if ( bparam.stFtpParam.byMode == 1 ) //passive { memset( cmd, 0x00, 128 ); sprintf( cmd, "pass\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); } #ifdef CUSTOM_DIR char sub_temp[ 128 ]; memset(sub_temp, 0, 128); sprintf(sub_temp, "%s/%s", bparam.stFtpParam.szFtpDir,bparam.stIEBaseParam.dwDeviceID); //strcpy(sub_temp, bparam.stFtpParam.szFtpDir); flag = sub_dir(fp,sub_temp); if(flag){ memset( cmd, 0x00, 128 ); sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir ); fwrite( cmd, 1, strlen( cmd ), fp ); } #else memset( cmd, 0x00, 128 ); sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir ); fwrite( cmd, 1, strlen( cmd ), fp ); #endif #ifdef CREATE_FTP_SUBDIRECTORY /* BEGIN: Added by wupm, 2013/2/1 Version:6 */ //filename=[/tmp/00_3a_58_19_3E_00__1_20130131110813_4.jpg] //[ /tmp/00_02_2A_F3_08_DC_JWEV-007533-LVFBH_0_20130425053328_8.jpg if ( 1 ) { int nFileNameLen = 0; char szTemp[128]; memset( szTemp, 0, 128 ); /* BEGIN: Added by wupm, 2013/6/14 */ #ifdef FTP_SUBDIRECTORY_UID_OR_MAC if ( bparam.stIEBaseParam.dwDeviceID[0] == 0 ) { memcpy(szTemp, bparam.stIEBaseParam.szMac, 17); szTemp[2] = '-'; szTemp[5] = '-'; szTemp[8] = '-'; szTemp[11] = '-'; szTemp[14] = '-'; } else { /* BEGIN: Modified by wupm, 2013/7/1 */ //strcpy(szTemp, bparam.stIEBaseParam.dwDeviceID[0]); strcpy(szTemp, bparam.stIEBaseParam.dwDeviceID); } Textout( "FTP Sub Directory = [%s]", szTemp ); memset( cmd, 0x00, 128 ); #else /* BEGIN: Modified by wupm, 2013/4/25 */ //nFileNameLen = strlen( szTemp ); nFileNameLen = strlen( filename ); memcpy( szTemp, filename + nFileNameLen - 20, 8 ); Textout("FileName = {%s}", filename); Textout("cap File name = [%s]", capfilename); Textout( "FTP Sub Directory = [%s]", szTemp ); memset( cmd, 0x00, 128 ); #endif /* BEGIN: Modified by wupm, 2013/4/25 */ //sprintf( cmd, "mkdir -p %s\n", szTemp ); sprintf( cmd, "mkdir %s\n", szTemp ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "cd %s\n", szTemp ); fwrite( cmd, 1, strlen( cmd ), fp ); } #endif /* END: Added by wupm, 2013/2/1 */ memset( cmd, 0x00, 128 ); sprintf( cmd, "lcd /tmp\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); if ( test == 0x01 ) { FtpFileTest(); memset( cmd, 0x00, 128 ); sprintf( cmd, "put ftptest.txt\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); } else { char filename1[128]; char filename2[32]; memset( filename1, 0x00, 128 ); memcpy( filename1, filename + 5, strlen( filename ) - 5 ); memset( filename2, 0x00, 32 ); memcpy( filename2, capfilename + 5, strlen( capfilename ) - 5 ); memset( cmd, 0x00, 128 ); sprintf( cmd, "put %s %s\n", filename2, filename1 ); Textout("COMMAND = [%s]", cmd); fwrite( cmd, 1, strlen( cmd ), fp ); } memset( cmd, 0x00, 128 ); sprintf( cmd, "close\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "bye\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); memset( cmd, 0x00, 128 ); sprintf( cmd, "!\n" ); fwrite( cmd, 1, strlen( cmd ), fp ); /* BEGIN: Added by wupm, 2013/4/25 */ /* BEGIN: Deleted by Baggio.wu, 2013/7/19 */ //move to where file create #if 0 memset( cmd, 0x00, 128 ); sprintf(cmd, "rm -f %s", capfilename); fwrite( cmd, 1, strlen( cmd ), fp ); #endif fclose( fp ); iRet = access( "/tmp/ftpupdate.sh", X_OK ); if ( iRet ) { DoSystem( "chmod a+x /tmp/ftpupdate.sh" ); } return 0; }
void PMenu::writeConfig( QDir base_dir, PMenuItem *parent_item) { if( parent_item ) if( parent_item->read_only ) return; if( !base_dir.exists() ) { return; } QString name; const QStrList *temp_list = base_dir.entryList("*", QDir::Files); QStrList file_list; file_list.setAutoDelete(TRUE); QStrListIterator temp_it( *temp_list ); while( name = temp_it.current() ) { file_list.append(name); ++temp_it; } temp_list = base_dir.entryList("*", QDir::Dirs); QStrList dir_list; dir_list.setAutoDelete(TRUE); temp_it.toFirst(); while( name = temp_it.current() ) { if(name != "." && name != "..") dir_list.append(name); ++temp_it; } QString sort_order; PMenuItem *item; for( item = list.first(); item != 0; item = list.next() ) { // if( item->read_only ) // continue; if( item->entry_type == separator ) sort_order += ((QString) "SEPARATOR" + ','); else sort_order += (item->real_name + ','); if( item->getType() == submenu ) { if( !item->read_only ) { QDir sub_dir(base_dir); if( !sub_dir.cd(item->real_name) ) { base_dir.mkdir(item->real_name); if( !sub_dir.cd(item->real_name) ) continue; } item->sub_menu->writeConfig( sub_dir, item ); } dir_list.remove(item->real_name); } else { if( item->entry_type != separator ) { if( !item->read_only ) { if( item->real_name.isEmpty() ) item->real_name = uniqueFileName(item->text_name); item->writeConfig(base_dir); } file_list.remove(item->real_name); // + ".kdelnk"); } } } // remove files not in pmenu for( name = file_list.first(); name != 0; name = file_list.next() ) { if( isKdelnkFile(base_dir.absFilePath(name)) ) { //debug("will remove file: %s", (const char *) name ); base_dir.remove(name); } } // remove dirs not in pmenu for( name = dir_list.first(); name != 0; name = dir_list.next() ) { //debug("will remove dir: %s", (const char *) name ); QDir sub_dir(base_dir); if(sub_dir.cd(name)) { PMenu *new_menu = new PMenu; new_menu->writeConfig(sub_dir); delete new_menu; sub_dir.remove(".directory"); } base_dir.rmdir(name); } sort_order.truncate(sort_order.length()-1); QString file = base_dir.absPath(); file += "/.directory"; QFile config(file); if( !config.open(IO_ReadWrite) ) return; config.close(); KConfig kconfig(file); kconfig.setGroup("KDE Desktop Entry"); kconfig.writeEntry("SortOrder", sort_order); if( parent_item ) { kconfig.writeEntry("MiniIcon", parent_item->pixmap_name ); if( parent_item->big_pixmap_name.isEmpty() ) parent_item->big_pixmap_name = "folder.xpm"; kconfig.writeEntry("Icon", parent_item->big_pixmap_name ); kconfig.writeEntry("Name", parent_item->text_name, TRUE, FALSE, TRUE ); } kconfig.sync(); }