diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2007-08-09 16:06:27 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2007-08-09 16:06:27 +0000 |
commit | 8dbc7e350b9ec9a5461eefe0437d5d484b8bd534 (patch) | |
tree | a940107410715a35dc4bcafb9bb9f012ccde42b6 /rbutil/rbutilqt/installzip.cpp | |
parent | 965881fd8559101d6782ebf37a03687ef98b0558 (diff) | |
download | rockbox-8dbc7e350b9ec9a5461eefe0437d5d484b8bd534.tar.gz rockbox-8dbc7e350b9ec9a5461eefe0437d5d484b8bd534.zip |
add voice file installation. This also extends the ZipInstaller class a bit to handle copying the downloaded file instead of unzipping.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14256 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/installzip.cpp')
-rw-r--r-- | rbutil/rbutilqt/installzip.cpp | 88 |
1 files changed, 57 insertions, 31 deletions
diff --git a/rbutil/rbutilqt/installzip.cpp b/rbutil/rbutilqt/installzip.cpp index 4f99d7bc31..4e2ab518ba 100644 --- a/rbutil/rbutilqt/installzip.cpp +++ b/rbutil/rbutilqt/installzip.cpp | |||
@@ -24,7 +24,7 @@ | |||
24 | 24 | ||
25 | ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) | 25 | ZipInstaller::ZipInstaller(QObject* parent): QObject(parent) |
26 | { | 26 | { |
27 | 27 | m_unzip = true; | |
28 | } | 28 | } |
29 | 29 | ||
30 | 30 | ||
@@ -62,7 +62,7 @@ void ZipInstaller::downloadRequestFinished(int id, bool error) | |||
62 | void ZipInstaller::downloadDone(bool error) | 62 | void ZipInstaller::downloadDone(bool error) |
63 | { | 63 | { |
64 | qDebug() << "Install::downloadDone, error:" << error; | 64 | qDebug() << "Install::downloadDone, error:" << error; |
65 | 65 | QStringList zipContents; // needed later | |
66 | // update progress bar | 66 | // update progress bar |
67 | 67 | ||
68 | int max = m_dp->getProgressMax(); | 68 | int max = m_dp->getProgressMax(); |
@@ -85,37 +85,63 @@ void ZipInstaller::downloadDone(bool error) | |||
85 | } | 85 | } |
86 | else m_dp->addItem(tr("Download finished."),LOGOK); | 86 | else m_dp->addItem(tr("Download finished."),LOGOK); |
87 | 87 | ||
88 | // unzip downloaded file | 88 | if(m_unzip) { |
89 | qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint; | 89 | // unzip downloaded file |
90 | 90 | qDebug() << "about to unzip the downloaded file" << m_file << "to" << m_mountpoint; | |
91 | m_dp->addItem(tr("Extracting file."),LOGINFO); | 91 | |
92 | 92 | m_dp->addItem(tr("Extracting file."),LOGINFO); | |
93 | qDebug() << "file to unzip: " << m_file; | 93 | |
94 | UnZip::ErrorCode ec; | 94 | qDebug() << "file to unzip: " << m_file; |
95 | UnZip uz; | 95 | UnZip::ErrorCode ec; |
96 | ec = uz.openArchive(m_file); | 96 | UnZip uz; |
97 | if(ec != UnZip::Ok) { | 97 | ec = uz.openArchive(m_file); |
98 | m_dp->addItem(tr("Opening archive failed: %1.") | 98 | if(ec != UnZip::Ok) { |
99 | .arg(uz.formatError(ec)),LOGERROR); | 99 | m_dp->addItem(tr("Opening archive failed: %1.") |
100 | m_dp->abort(); | 100 | .arg(uz.formatError(ec)),LOGERROR); |
101 | emit done(false); | 101 | m_dp->abort(); |
102 | return; | 102 | downloadFile.remove(); |
103 | emit done(false); | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | ec = uz.extractAll(m_mountpoint); | ||
108 | if(ec != UnZip::Ok) { | ||
109 | m_dp->addItem(tr("Extracting failed: %1.") | ||
110 | .arg(uz.formatError(ec)),LOGERROR); | ||
111 | m_dp->abort(); | ||
112 | downloadFile.remove(); | ||
113 | emit done(false); | ||
114 | return; | ||
115 | } | ||
116 | // prepare file list for log | ||
117 | zipContents = uz.fileList(); | ||
103 | } | 118 | } |
104 | 119 | else { | |
105 | ec = uz.extractAll(m_mountpoint); | 120 | // only copy the downloaded file to the output location / name |
106 | if(ec != UnZip::Ok) { | 121 | m_dp->addItem(tr("Installing file."), LOGINFO); |
107 | m_dp->addItem(tr("Extracting failed: %1.") | 122 | qDebug() << "saving downloaded file (no extraction)"; |
108 | .arg(uz.formatError(ec)),LOGERROR); | 123 | |
109 | m_dp->abort(); | 124 | downloadFile.open(); // copy fails if file is not opened (filename issue?) |
110 | emit done(false); | 125 | // make sure the required path is existing |
111 | return; | 126 | QString path = QFileInfo(m_mountpoint + m_target).absolutePath(); |
127 | QDir p; | ||
128 | p.mkpath(path); | ||
129 | // QFile::copy() doesn't overwrite files, so remove old one first | ||
130 | QFile(m_mountpoint + m_target).remove(); | ||
131 | if(!downloadFile.copy(m_mountpoint + m_target)) { | ||
132 | m_dp->addItem(tr("Installing file failed."), LOGERROR); | ||
133 | m_dp->abort(); | ||
134 | downloadFile.remove(); | ||
135 | emit done(false); | ||
136 | return; | ||
137 | } | ||
138 | |||
139 | // add file to log | ||
140 | zipContents.append(m_mountpoint + m_target); | ||
112 | } | 141 | } |
113 | 142 | ||
114 | m_dp->addItem(tr("creating installation log"),LOGINFO); | 143 | m_dp->addItem(tr("Creating installation log"),LOGINFO); |
115 | 144 | QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); | |
116 | QStringList zipContents = uz.fileList(); | ||
117 | |||
118 | QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); | ||
119 | 145 | ||
120 | installlog.beginGroup(m_logsection); | 146 | installlog.beginGroup(m_logsection); |
121 | for(int i = 0; i < zipContents.size(); i++) | 147 | for(int i = 0; i < zipContents.size(); i++) |
@@ -127,7 +153,7 @@ void ZipInstaller::downloadDone(bool error) | |||
127 | // remove temporary file | 153 | // remove temporary file |
128 | downloadFile.remove(); | 154 | downloadFile.remove(); |
129 | 155 | ||
130 | m_dp->addItem(tr("Extraction finished successfully."),LOGOK); | 156 | m_dp->addItem(tr("Installation finished successfully."),LOGOK); |
131 | m_dp->abort(); | 157 | m_dp->abort(); |
132 | emit done(false); | 158 | emit done(false); |
133 | } | 159 | } |