OSDN Git Service

バージョン情報取得機能 httpsに対応
authorqw_fuku <fkhideaki@gmail.com>
Sat, 7 Nov 2015 05:19:03 +0000 (14:19 +0900)
committerqw_fuku <fkhideaki@gmail.com>
Sat, 7 Nov 2015 05:19:03 +0000 (14:19 +0900)
Src/QtGeoViewer/PathInfo.cpp
Src/QtGeoViewer/PathInfo.h
Src/QtGeoViewer/QGVAboutDlg.cpp
Src/QtGeoViewer/QGVAboutDlg.h

index 50d649b..a8808ae 100644 (file)
@@ -13,6 +13,7 @@ static char* POSITION_CONFIG    = "position.ini";
 static char* WINLAYOUT_CONFIG   = "window_layout.dat";
 static char* GUI_CONFIG         = "gui_config.xml";
 static char* CAMERA_RECORD      = "camera_record.camera";
+
 static char* DEFAULT_CONFIG_DIR = "/Data/DefaultConfig/";
 
 
@@ -32,6 +33,20 @@ QString PathInfo::GetLocalAppDirPath(void)
        return QStandardPaths::writableLocation(loc_type);
 }
 
+QString PathInfo::GetTempDirPath(void)
+{
+       QStandardPaths::StandardLocation loc_type;
+       loc_type = QStandardPaths::TempLocation;
+
+       return QStandardPaths::writableLocation(loc_type);
+}
+
+
+QString PathInfo::GetAppTmpPath(void)
+{
+       return GetLocalAppDirPath() + "/Tmp/";
+}
+
 QString PathInfo::GetConfigDirPath(void)
 {
        if (BUILDMODE_RELEASE)
index 6ee3693..0b56ccb 100644 (file)
@@ -9,7 +9,9 @@ class PathInfo
 public:
        static QString GetMyDocDirPath(void);
        static QString GetLocalAppDirPath(void);
+       static QString GetTempDirPath(void);
 
+       static QString GetAppTmpPath(void);
        static QString GetConfigDirPath(void);
        static QString GetPosConfigFilePath(void);
 
index 24f2d7b..13078ff 100644 (file)
@@ -5,12 +5,18 @@
 #include <QDesktopServices>
 #include <QUrl>
 #include <QDomDocument>
+#include <QDir>
 
 #include <Qt5Utility/QXmlExt.h>
 
 #include "BuildInfo.h"
 #include "DownloadManager.h"
 #include "AppVersion.h"
+#include "PathInfo.h"
+
+#include "../../Lib/Qt5Utility/ExtCmdRunner.h"
+
+
 
 static const char* PROJECT_URL = "https://osdn.jp/projects/qtgeoviewer/";
 static const char* RELEASE_RSS = "https://osdn.jp/projects/qtgeoviewer/releases/rss";
@@ -97,14 +103,23 @@ bool QGVAboutDlg::GetVersionFromWeb(AppVersion& version, QString& vs)
 
 bool QGVAboutDlg::GetVersionTextFromWeb(QString& version)
 {
-       QByteArray ba;
-       if (!DownloadReleaseRSS(ba))
+       if (!DownloadReleaseRSS())
                return false;
 
-       QString src(ba);
+       QFile file(GetTmpPath());
+       if (!file.open(QIODevice::ReadOnly))
+               return false;
 
        QDomDocument xml;
-       xml.setContent(src);
+       xml.setContent(&file);
+
+       bool suc = ReadXmlBuf(xml, version);
+       file.close();
+       return suc;
+}
+
+bool QGVAboutDlg::ReadXmlBuf(QDomDocument& xml, QString& version)
+{
        QXML_ELEM_FOREACH(n_rss, xml)
        {
                QXML_ELEM_FOREACH(n_channel, n_rss)
@@ -139,20 +154,37 @@ bool QGVAboutDlg::GetVersionTextFromWeb(QString& version)
        return false;
 }
 
-bool QGVAboutDlg::DownloadReleaseRSS(QByteArray& buf)
+QString QGVAboutDlg::GetTmpPath(void)
+{
+       QString dst = PathInfo::GetAppTmpPath();
+       dst = QDir::toNativeSeparators(dst);
+       dst += "version.xml";
+       return dst;
+}
+
+bool QGVAboutDlg::DownloadReleaseRSS(void)
 {
-       DownloadManager manager;
-       manager.downloadToBuf(QUrl(RELEASE_RSS), &buf);
+       QString url = RELEASE_RSS;
+       QString dst = GetTmpPath();
 
-       manager.WaitWhileDownloading();
+       QString tmp_dir = PathInfo::GetAppTmpPath();
+       if (!QDir().exists(tmp_dir))
+               QDir().mkpath(tmp_dir);
 
-       if (manager.currentState() == DownloadManager::DownloadFail)
-               return false;
+       if (QFile(dst).exists())
+               QFile::remove(dst);
 
-       return true;
-}
+       ExtCmdRunner runner;
+       runner.cmd = PathInfo::GetWebDownloaderPath();
+       runner.args = "";
+       runner.args += url;
+       runner.args += " ";
+       runner.args += dst;
+
+       runner.Execute2(ShellExecMode::Wait);
+
+       if (!QFile(dst).exists())
+               return false;
 
-bool QGVAboutDlg::ParseVersion(QString& line, QString& version)
-{
        return true;
 }
index 6e0bf87..7061bf9 100644 (file)
@@ -6,6 +6,8 @@
 #include "AppVersion.h"
 
 
+class QDomDocument;
+
 class QGVAboutDlg : public QDialog
 {
        Q_OBJECT
@@ -20,11 +22,14 @@ private:
        bool GetVersionFromWeb(AppVersion& version, QString& vs);
        bool GetVersionTextFromWeb(QString& version);
        bool VersionTextToVal(QString& version);
-       bool DownloadReleaseRSS(QByteArray& buf);
-       bool ParseVersion(QString& line, QString& version);
+       bool DownloadReleaseRSS(void);
 
        void ShowProjectPage(void);
 
+       QString GetTmpPath(void);
+
+       bool ReadXmlBuf(QDomDocument& xml, QString& version);
+
 private slots:
        void on_buttonBox_accepted();