📄 mpkgtool.cpp
字号:
/* * mpkgTool program for EZX * Copyright (C) 2007 Lasly <Flylasly@gmail.com> * *///#define QT_NO_TEXTCODEC#define QT_NO_DRAGANDDROP#define QT_NO_PROPERTIES#include <E2_EZX_ZApplication.h>#include <E2_EZX_ZKbMainWidget.h>#include <E2_EZX_ZMessageDlg.h>#include <E2_EZX_ZLabel.h>#include <E2_EZX_ZScrollPanel.h>#include <E2_EZX_ZSoftKey.h>#include <E2_EZX_ZOptionsMenu.h>#include <E2_EZX_ZComboBox.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <qfile.h>#include <qtextcodec.h>#include <qlayout.h>#include <qdir.h>#include <pthread.h>
QTextCodec* gbk_codec = QTextCodec::codecForName("UTF-8");
QString ChineseAndEnglish(const char*ChineseString)
{
return gbk_codec->toUnicode(ChineseString);
} typedef struct MpkgProgram{ char name[64]; char showName[24]; char path[96]; char id[48]; int domain; int isCard;};int initMpkgProgram(MpkgProgram** pplist ){ QDir dir("/ezxlocal/.system/QTDownLoad"); int count = (int)dir.count(); dir.setPath("/mmc/mmca1/.system/QTDownLoad"); count += (int)dir.count(); *pplist = new MpkgProgram[count]; int index = 0; if(*pplist != NULL ) { QFile file("/mmc/mmca1/.system/java/CardRegistry"); int isMpkg = 0; char tmp[256]; if( file.open(IO_ReadWrite) ) { isMpkg = 0; while( file.readLine( tmp, 256 ) != -1 && index < count) { if( tmp[0] == '[' ) { if( isMpkg ) { index++; isMpkg = 0; } (*pplist)[index].isCard = 1; strcpy( (*pplist)[index].id , tmp); } else if( strstr( tmp , "Directory" ) == tmp ) { strcpy( (*pplist)[index].path , "/mmc/mmca1/.system/QTDownLoad/" ); strcat( (*pplist)[index].path , tmp + 12 ); (*pplist)[index].path[strlen((*pplist)[index].path) - 1 ] = 0; } else if( strstr( tmp , "Name" ) == tmp ) { strcpy( (*pplist)[index].name , tmp + 7 ); (*pplist)[index].name[strlen((*pplist)[index].name) - 1 ] = 0; if( strlen((*pplist)[index].name) > 20 ) { memset((*pplist)[index].showName , 0 , 24 ); strncpy( (*pplist)[index].showName , (*pplist)[index].name , 16 ); strcat( (*pplist)[index].showName , "..." ); } else { strcpy( (*pplist)[index].showName , (*pplist)[index].name ); } } else if( strstr( tmp , "GroupID" ) == tmp ) { if( strstr( tmp , "ezx" ) != NULL ) { (*pplist)[index].domain = 0; } else { (*pplist)[index].domain = 1; } } else if( strstr( tmp , "MpkgFile" ) == tmp ) { if( strchr( tmp , '/' ) != NULL ) { isMpkg = 1; } } } file.close(); } if( isMpkg ) { index++; } isMpkg = 0;// copy ^o^ QFile filephone("/ezx_user/download/appwrite/am/InstalledDB"); if( filephone.open(IO_ReadWrite) ) { while( filephone.readLine( tmp, 256 ) != -1 && index < count ) { if( tmp[0] == '[' ) { if( isMpkg ) { index++; isMpkg = 0; } (*pplist)[index].isCard = 0; strcpy( (*pplist)[index].id , tmp); } else if( strstr( tmp , "Directory" ) == tmp ) { strcpy( (*pplist)[index].path , "/ezxlocal/.system/QTDownLoad/" ); strcat( (*pplist)[index].path , tmp + 12 ); (*pplist)[index].path[strlen((*pplist)[index].path) - 1 ] = 0; } else if( strstr( tmp , "Name" ) == tmp ) { strcpy( (*pplist)[index].name , tmp + 7 ); (*pplist)[index].name[strlen((*pplist)[index].name) - 1 ] = 0; if( strlen((*pplist)[index].name) > 20 ) { memset((*pplist)[index].showName , 0 , 24 ); strncpy( (*pplist)[index].showName , (*pplist)[index].name , 16 ); strcat( (*pplist)[index].showName , "..." ); } else { strcpy( (*pplist)[index].showName , (*pplist)[index].name ); } } else if( strstr( tmp , "GroupID" ) == tmp ) { if( strstr( tmp , "ezx" ) != NULL ) { (*pplist)[index].domain = 0; } else { (*pplist)[index].domain = 1; } } else if( strstr( tmp , "MpkgFile" ) == tmp ) { if( strchr( tmp , '/' ) != NULL ) { isMpkg = 1; } } } filephone.close(); } if( isMpkg ) { index++; } } if( index == 0 ) { system("showQ \"\" 没有安装任何mpkg程序! 2"); exit(0); } return index;}void setDomain(char* id , int domain , int isCard){ char tmp[256]; if( isCard ) { strcpy( tmp , "/mmc/mmca1/.system/java/CardRegistry"); } else { strcpy( tmp , "/ezx_user/download/appwrite/am/InstalledDB"); } QFile file(tmp); if( file.open(IO_ReadWrite) ) { printf(tmp); int size = file.size(); char* buff = new char[size]; file.readBlock(buff , size); file.close(); file.remove(); if( file.open(IO_ReadWrite) ) { char* pre = strstr(buff , id); char* pgroup = strstr( pre , "\nGroupID" ); file.writeBlock(buff , pgroup - buff + 11 ); switch( domain ) { case 1: file.writeBlock("root" , 4 ); break; case 0: default: file.writeBlock("ezx" , 3 ); break; } pre = strchr( pgroup + 1, '\n' ); char* puserid = strstr( pre , "\nUserID" ); file.writeBlock(pre , puserid - pre + 10 ); switch( domain ) { case 1: file.writeBlock("root" , 4 ); break; case 0: default: file.writeBlock("ezx" , 3 ); break; } pre = strchr( puserid + 1, '\n' ); file.writeBlock(pre , size - ( pre - buff ) ); } file.close(); delete[] buff; }} void* removeMpkg(void* p );
class MyDialog : public ZKbMainWidget{
Q_OBJECTpublic: ZComboBox* nameBox; ZComboBox* domainBox; ZLabel* infoLabel; MpkgProgram* pMpkgList; MyDialog( ):ZKbMainWidget((ZHeader::HEADER_TYPE)3,NULL , "ZMainWidget" , 0) { setMainWidgetTitle(ChineseAndEnglish("mpkg管理工具")); ZSoftKey* softKey = new ZSoftKey(NULL , this , this); QRect rect; ZOptionsMenu* menu = new ZOptionsMenu(rect, softKey, NULL , 0 ,(ZSkinService::WidgetClsID)2 ); menu->insertItem(ChineseAndEnglish("卸载") , NULL , NULL , true , 0 , 0 ); menu->insertItem(ChineseAndEnglish("退出") , NULL , NULL , true , 1 , 1 ); softKey->setOptMenu(ZSoftKey::LEFT, menu); softKey->setText(ZSoftKey::LEFT, ChineseAndEnglish("选项"), (ZSoftKey::TEXT_PRIORITY)0); softKey->setText(ZSoftKey::RIGHT, ChineseAndEnglish("关于"), (ZSoftKey::TEXT_PRIORITY)0);
softKey->setClickedSlot(ZSoftKey::RIGHT, this, SLOT(about()));
menu->connectItem(0, this, SLOT(remove()));
menu->connectItem(1, qApp, SLOT(quit())); nameBox = new ZComboBox(this,"name",true); domainBox = new ZComboBox(this,"domainBox",true); infoLabel = new ZLabel(ChineseAndEnglish("") , this, "ZLabel", 0, (ZSkinService::WidgetClsID)4); infoLabel->setPreferredWidth(240); infoLabel->setAutoResize(true ); initNameBox(); domainBox->insertItem(ChineseAndEnglish("ezx"), 0 ); domainBox->insertItem(ChineseAndEnglish("root"), 1 ); QVBoxLayout* layout = getVBoxLayout(); ZScrollPanel *zsv = new ZScrollPanel(this , NULL , 0 , (ZSkinService::WidgetClsID)4); int height = heightForWidth(240) + 10; zsv->addChild(nameBox , 10 , height); height += (nameBox->getContentRect()).height() + nameBox->getBtnHSpacing() * 4 ; zsv->addChild(domainBox , 10 , height); height += (domainBox->getContentRect()).height() + domainBox->getBtnHSpacing() * 4 ; zsv->addChild(infoLabel , 10 , height); layout->addWidget(zsv); setSoftKey(softKey); dlg = NULL; startTimer(500); currentIndex = -1; } ~MyDialog( ) { killTimers(); if( pMpkgList != NULL ) { delete[] pMpkgList; } if( dlg != NULL ) { delete dlg; } } void initNameBox() { int number = initMpkgProgram( &pMpkgList ); nameBox->clear(); for( int i = 0 ; i < number ; i++ ) { nameBox->insertItem(ChineseAndEnglish(pMpkgList[i].showName), i ); } if( number > 0 ) { nameBox->setCurrentItem( 0 ); } else { delete[] pMpkgList; pMpkgList = NULL; QString a = ChineseAndEnglish("Error"); QString b = ChineseAndEnglish("没有安装任何mpkg程序!"); ZMessageDlg* d = new ZMessageDlg(a , b , (ZMessageDlg::MessageDlgType)2 , 0 , this , "about" , true , 0); qApp->setMainWidget( d ); d->show(); } } ZMessageDlg *dlg; int currentIndex; int currentDomian;public slots: virtual void timerEvent(QTimerEvent* e) { if( pMpkgList == NULL ) { ZKbMainWidget::timerEvent(e); return; } int select = nameBox->currentItem(); if( currentIndex != select ) { char tmp[256]; sprintf( tmp , "名称:%s\n位置:%s\n路径:%s" , pMpkgList[select].name , pMpkgList[select].isCard == 0 ? "手机" : "内存卡" , pMpkgList[select].path ); infoLabel->setText(ChineseAndEnglish(tmp)); infoLabel->setPreferredWidth(220); infoLabel->setAutoResize(true ); domainBox->setCurrentItem(pMpkgList[select].domain); currentIndex = select; currentDomian = domainBox->currentItem(); } if( currentDomian != domainBox->currentItem() ) { setDomain( pMpkgList[select].id , domainBox->currentItem() , pMpkgList[select].isCard); currentDomian = domainBox->currentItem(); pMpkgList[select].domain = currentDomian; } ZKbMainWidget::timerEvent(e); } void remove() { pthread_t remove; pthread_create( &remove , NULL , removeMpkg , this); } void about() { if( dlg == NULL ) { QString a = ChineseAndEnglish("关于"); QString b = ChineseAndEnglish("mpkg管理工具 ver1.0\nby Lasly\nEmail: flylasly@gmail.com"); dlg = new ZMessageDlg(a , b , (ZMessageDlg::MessageDlgType)2 , 0 , this , "about" , true , 0); } dlg->show(); }};void* removeMpkg(void* p ){ char tmp[256]; MyDialog* dialog = (MyDialog*)p; int index = dialog->nameBox->currentItem(); sprintf(tmp , "showQ 删除MPKG \"是否删除%s?\n删除不可恢复\" 1" , dialog->pMpkgList[index].name ); if( system(tmp) ) { if( dialog->pMpkgList[index].isCard ) { strcpy( tmp , "/mmc/mmca1/.system/java/CardRegistry"); } else { strcpy( tmp , "/ezx_user/download/appwrite/am/InstalledDB"); } QFile file(tmp); if( file.open(IO_ReadWrite) ) { printf(tmp); int size = file.size(); char* buff = new char[size]; file.readBlock(buff , size); file.close(); file.remove(); if( file.open(IO_ReadWrite) ) { char* pre = strstr(buff , dialog->pMpkgList[index].id); file.writeBlock(buff , pre - buff ); pre = strstr(pre+ 1 , "\n[" ); if( pre != NULL ) { file.writeBlock(pre + 1 , size - ( pre - buff ) - 1); } file.close(); } } sprintf(tmp , "rm -rf %s " , dialog->pMpkgList[index].path ); system(tmp); system( "showQ 完成 删除完成,请重启手机 2"); } dialog->initNameBox(); return NULL;}int main( int argc, char **argv ){ ZApplication* a = new ZApplication( argc, argv ); MyDialog* w = new MyDialog(); a->setMainWidget( w ); w->show(); int ret = a->exec(); delete w; delete a; return ret;}#include "helloworld.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -