-
+// Copyright (C) 2013 James Turner - zakalawe@mac.com
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
#include <simgear/package/Install.hxx>
virtual void responseHeadersComplete()
{
- std::cout << "starting download of " << m_owner->package()->id() << " from "
- << url() << std::endl;
Dir d(m_extractPath);
d.create(0755);
- memset(&m_md5, 0, sizeof(MD5_CTX));
- MD5Init(&m_md5);
+ memset(&m_md5, 0, sizeof(SG_MD5_CTX));
+ SG_MD5Init(&m_md5);
}
virtual void gotBodyData(const char* s, int n)
{
m_buffer += std::string(s, n);
- MD5Update(&m_md5, (unsigned char*) s, n);
+ SG_MD5Update(&m_md5, (unsigned char*) s, n);
+
+ m_owner->installProgress(m_buffer.size(), responseLength());
}
- virtual void responseComplete()
+ virtual void onDone()
{
if (responseCode() != 200) {
SG_LOG(SG_GENERAL, SG_ALERT, "download failure");
- doFailure();
+ doFailure(Delegate::FAIL_DOWNLOAD);
return;
}
- MD5Final(&m_md5);
+ SG_MD5Final(&m_md5);
// convert final sum to hex
const char hexChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
std::stringstream hexMd5;
<< "\t" << hexMd5.str() << "\n\t"
<< m_owner->package()->md5() << "\n\t"
<< "downloading from:" << url());
- doFailure();
+ doFailure(Delegate::FAIL_CHECKSUM);
return;
- } else {
- std::cout << "MD5 checksum is ok" << std::endl;
}
if (!extractUnzip()) {
SG_LOG(SG_GENERAL, SG_WARN, "zip extraction failed");
- doFailure();
+ doFailure(Delegate::FAIL_EXTRACT);
return;
}
}
m_extractPath.append(m_owner->package()->id());
- m_extractPath.rename(m_owner->path());
+ bool ok = m_extractPath.rename(m_owner->path());
+ if (!ok) {
+ doFailure(Delegate::FAIL_FILESYSTEM);
+ return;
+ }
+
m_owner->m_revision = m_owner->package()->revision();
m_owner->writeRevisionFile();
+ m_owner->installResult(Delegate::FAIL_SUCCESS);
}
private:
return result;
}
- void doFailure()
+ void doFailure(Delegate::FailureCode aReason)
{
Dir dir(m_extractPath);
dir.remove(true /* recursive */);
+
if (m_urls.size() == 1) {
-
+ std::cout << "failure:" << aReason << std::endl;
+ m_owner->installResult(aReason);
return;
}
+ std::cout << "retrying download" << std::endl;
m_urls.erase(m_urls.begin()); // pop first URL
}
Install* m_owner;
string_list m_urls;
- MD5_CTX m_md5;
+ SG_MD5_CTX m_md5;
std::string m_buffer;
SGPath m_extractPath;
};
}
m_download = new PackageArchiveDownloader(this);
- m_package->catalog()->root()->getHTTPClient()->makeRequest(m_download);
+ m_package->catalog()->root()->makeHTTPRequest(m_download);
+ m_package->catalog()->root()->startInstall(this);
}
void Install::uninstall()
delete this;
}
+void Install::installResult(Delegate::FailureCode aReason)
+{
+ if (aReason == Delegate::FAIL_SUCCESS) {
+ m_package->catalog()->root()->finishInstall(this);
+ } else {
+ m_package->catalog()->root()->failedInstall(this, aReason);
+ }
+}
+
+void Install::installProgress(unsigned int aBytes, unsigned int aTotal)
+{
+ m_package->catalog()->root()->installProgress(this, aBytes, aTotal);
+}
+
+
} // of namespace pkg
} // of namespace simgear