forked from Michael33881/adbLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstalldialog.cpp
executable file
·157 lines (101 loc) · 2.81 KB
/
uninstalldialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "uninstalldialog.h"
#include "ui_uninstalldialog.h"
#include <QProcess>
#include <QFile>
#include <QString>
#include <QMessageBox>
#include <QStringList>
#include <QTextStream>
#ifdef Q_OS_LINUX
int ost=0;
#elif defined(Q_OS_WIN)
int ost=1;
#elif defined(Q_OS_MAC)
int ost=2;
#endif
QString tmpdir;
QString tmpstr;
QString commstr;
QString cstr;
QString argument;
QString adb2;
QString fline;
QString uninstallDialog::packageName() {
if( ui->unlistWidget->selectedItems().count() == 1 )
return ui->unlistWidget->currentItem()->text();
else return "";
}
bool uninstallDialog::keepBox() {
return ui->keepBox->isChecked();
}
void uninstallDialog::setdescription(const QString &description)
{
ui->description->setText(description);
}
uninstallDialog::uninstallDialog(const QString &port, const QString &daddr,QWidget *parent) :
QDialog(parent),m_port(port),m_daddr(daddr),
ui(new Ui::uninstallDialog)
{
if (ost == 1)
{
tmpdir = "./";
adb2 = tmpdir+"adb.exe";
}
if (ost == 2)
{
tmpdir = QCoreApplication::applicationDirPath();
tmpdir = tmpdir+"/adbfiles/";
adb2 = tmpdir+"adb";
}
if (ost == 0)
{
tmpdir = QCoreApplication::applicationDirPath();
tmpdir = tmpdir+"/adbfiles/";
adb2 = tmpdir+"adb";
}
ui->setupUi(this);
tmpstr = tmpdir+"tempfl";
QString c1;
QProcess packages;
packages.setProcessChannelMode(QProcess::MergedChannels);
if (m_port.isEmpty())
argument = " -s "+m_daddr+ " shell pm list packages";
else
argument = " -s "+m_daddr+":"+m_port+" shell pm list packages";
cstr = adb2 + argument;
// QMessageBox::critical(0, "",cstr,QMessageBox::Cancel);
packages.start(cstr);
packages.waitForFinished(-1);
commstr=packages.readAll();
QFile file2(tmpstr);
if(!file2.open(QFile::WriteOnly |
QFile::Text))
{
QMessageBox::critical(this,"","Error creating file!");
return;
}
QTextStream out(&file2);
out << commstr << endl;
file2.flush();
file2.close();
QFile file3(tmpstr);
if (!file3.open(QIODevice::ReadOnly | QIODevice::Text))
{QMessageBox::critical(this,"","Error reading file!");
return; }
QTextStream in(&file3);
while (!in.atEnd())
{
fline = in.readLine();
if (!fline.isEmpty())
{
fline.remove(0,8);
ui->unlistWidget->addItem(fline);
}
}
file3.close();
QFile::remove(tmpstr);
}
uninstallDialog::~uninstallDialog()
{
delete ui;
}