Browse Source

V0.3.1
1、FTP下载文件完成
2、FTP创建文件夹完成

Apple 6 months ago
parent
commit
2fda5e2e21
7 changed files with 113 additions and 36 deletions
  1. 1 0
      .gitignore
  2. 7 0
      .vscode/launch.json
  3. 1 1
      External
  4. 6 0
      demo/ftp/CMakeLists.txt
  5. 89 35
      demo/ftp/widget.cpp
  6. 2 0
      demo/ftp/widget.h
  7. 7 0
      demo/ftp/widget.ui

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+External/

+ 7 - 0
.vscode/launch.json

@@ -0,0 +1,7 @@
+{
+    // 使用 IntelliSense 了解相关属性。 
+    // 悬停以查看现有属性的描述。
+    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": []
+}

+ 1 - 1
External

@@ -1 +1 @@
-D:/Design/Libraries/Standard
+/home/Apple/Lib/Standard_Library/

+ 6 - 0
demo/ftp/CMakeLists.txt

@@ -55,6 +55,12 @@ target_link_libraries(${this_exe} PRIVATE
     CURL::libcurl
 )
 
+if(CMAKE_CXX_COMPILER_VERSION LESS 9.0)
+    target_link_libraries(${this_exe} PRIVATE
+        stdc++fs
+    )
+endif()
+
 # target_link_libraries(${this_exe} PRIVATE
 #     ${CURL_LIBRARY}
     

+ 89 - 35
demo/ftp/widget.cpp

@@ -6,12 +6,14 @@
 #include <QNetworkRequest>
 #include <QTimer>
 #include <QNetworkProxy>
+#include <iostream>
 #include <regex>
 #include <stdlib.h>
 #include "QtFtp.h"
 
 #include "spdlog/spdlog.h"
 #include "fmtlog.h"
+#include "LightLog.h"
 
 
 Widget::Widget(QWidget *parent)
@@ -20,7 +22,7 @@ Widget::Widget(QWidget *parent)
 {
     ui->setupUi(this);
 
-    m_curlFtp.setFtpIPAndPort("192.168.50.100", "21");
+    m_curlFtp.setFtpIPAndPort("192.168.50.100", 21);
     m_curlFtp.setFtpUsernameAndPassword("microsoft", "19980714Lq");
 
     SPDLOG_INFO("***** Qt Library *****");
@@ -36,60 +38,112 @@ Widget::~Widget()
 void Widget::on_pBtn_connect_clicked()
 {
     SPDLOG_INFO("点击了“连接按钮”");
-    QString url = "ftp://192.168.50.100/SSD1/Picture/";
-    QString username = "microsoft";
-    QString password = "19980714Lq";
-
     std::vector<std::string> list;
-    CurlFtp::listFiles(url.toStdString(), username.toStdString(), password.toStdString(), list);
+    m_curlFtp.getFileList("/SSD2/Video", list);
     
     for(const std::string& filename : list)
     {
-        SPDLOG_INFO("{}", filename);
+        QString qfilename = QString::fromLocal8Bit(filename.c_str());
+        SPDLOG_INFO("{}", qfilename.toStdString());
     }
-
-    FMTLOG_INFO("***** Curl Library *****");
-    FMTLOG_INFO("{}","你好");
 }
 
-/* 使用Windows API进行编码转换 */
-char* G2U(const char* gb2312)
-{
-    int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
-    wchar_t* wstr = new wchar_t[len+1];
-    memset(wstr, 0, len+1);
-    MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
-    len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
-    char* str = new char[len+1];
-    memset(str, 0, len+1);
-    WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
-    if(wstr) delete[] wstr;
-    return str;
-}
+
 
 void Widget::on_pBtn_downloadFile_clicked()
 {
     SPDLOG_INFO("点击了“下载文件”");
     std::vector<std::string> fileList;
-    m_curlFtp.getFileList("/SSD1/Picture/", fileList);
+    bool ret = m_curlFtp.downloadFile("/SSD2/Video/哪吒之魔童降世.mp4", QApplication::applicationDirPath().toStdString() + "/哪吒之魔童降世.mp4");
+    if(ret)
+    {
+        SPDLOG_INFO("下载成功");
+    }
+    else
+    {
+        SPDLOG_INFO("下载失败");
+    }
 }
 
 void Widget::on_pBtn_downloadVideo_clicked()
 {
     SPDLOG_INFO("点击了“下载视频”");
-    std::shared_ptr<QtFtp> ftp = std::make_shared<QtFtp>();
-    ftp->setHostAndPort("192.168.50.100");
-    ftp->setUserPasswd("microsoft", "19980714Lq");
-    QString localPath = QApplication::applicationDirPath() + "/v1.mp4";
-    ftp->getFile(localPath, "/SSD1/Video/v1.mp4");
-    ftp->waitFinished(-1);
-    if(ftp->getResult())
+    // std::shared_ptr<QtFtp> ftp = std::make_shared<QtFtp>();
+    // ftp->setHostAndPort("192.168.50.100");
+    // ftp->setUserPasswd("microsoft", "19980714Lq");
+    // QString localPath = QApplication::applicationDirPath() + "/v1.mp4";
+    // ftp->getFile(localPath, "/SSD1/Video/v1.mp4");
+    // ftp->waitFinished(-1);
+    // if(ftp->getResult())
+    // {
+    //     SPDLOG_INFO("下载成功");
+    // }
+    // else
+    // {
+    //     SPDLOG_INFO("下载失败");
+    // }
+    bool ret = m_curlFtp.createDirectories("SSD1/DOC/123/234");
+    if(ret)
     {
-        SPDLOG_INFO("下载成功");
+        SPDLOG_INFO("文件夹创建成功");
+    }else {
+        SPDLOG_WARN("文件夹创建失败");
     }
-    else
+}
+
+void Widget::on_pBtn_logSpeed_clicked()
+{
+    SPDLOG_INFO("点击了“日志速度”");
+    /* 开始时间点1 */
+    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
+    for(int i = 0; i < 100000; i++)
     {
-        SPDLOG_INFO("下载失败");
+        SPDLOG_INFO("{}", "你好,这是日志速度的对比,这个是SPDLOG在打印日志");
+    }
+    /* 结束时间点1 */
+    std::chrono::steady_clock::time_point spdlogEnd = std::chrono::steady_clock::now();
+    for(int i = 0; i < 100000; i++)
+    {
+        FMTLOG_INFO("{}", "你好,这是日志速度的对比,这个是FMTLOG在打印日志");
+    }
+    std::chrono::steady_clock::time_point fmtlogEnd = std::chrono::steady_clock::now();
+    /* 使用std::cout */
+    for(int i = 0; i < 100000; i++)
+    {
+        std::cout << "你好,这是日志速度的对比," << "这个是std::cout在打印日志" << std::endl;
+    }
+    std::chrono::steady_clock::time_point coutEnd = std::chrono::steady_clock::now();
+    /* 使用printf */
+    for(int i = 0; i < 100000; i++)
+    {
+        printf("%s\n","你好,这是日志速度的对比,这个是printf在打印日志");
+    }
+    std::chrono::steady_clock::time_point printfEnd = std::chrono::steady_clock::now();
+    /* 使用QDebug */
+    for(int i = 0; i < 100000; i++)
+    {
+        qDebug() << "你好,这是日志速度的对比," << "这个是QDebug在打印日志";
+    }
+    std::chrono::steady_clock::time_point qDebugEnd = std::chrono::steady_clock::now();
+    /* 使用LightLog */
+    for(int i = 0; i < 100000; i++)
+    {
+        QLOG_INFO("你好,这是日志速度的对比," + "这个是LightLog在打印日志");
     }
+    std::chrono::steady_clock::time_point lightLogEnd = std::chrono::steady_clock::now();
+    /* 计算时间 */
+    std::chrono::duration<double> spdlogTime = std::chrono::duration_cast<std::chrono::duration<double>>(spdlogEnd - start);
+    std::chrono::duration<double> fmtlogTime = std::chrono::duration_cast<std::chrono::duration<double>>(fmtlogEnd - spdlogEnd);
+    std::chrono::duration<double> coutTime = std::chrono::duration_cast<std::chrono::duration<double>>(coutEnd - fmtlogEnd);
+    std::chrono::duration<double> printfTime = std::chrono::duration_cast<std::chrono::duration<double>>(printfEnd - coutEnd);
+    std::chrono::duration<double> qDebugTime = std::chrono::duration_cast<std::chrono::duration<double>>(qDebugEnd - printfEnd);
+    std::chrono::duration<double> lightLogTime = std::chrono::duration_cast<std::chrono::duration<double>>(lightLogEnd - qDebugEnd);
+    /* 打印时间 */
+    SPDLOG_INFO("SPDLOG打印耗时: {}", spdlogTime.count());
+    SPDLOG_INFO("FMTLOG打印耗时: {}", fmtlogTime.count());
+    SPDLOG_INFO("std::cout打印耗时: {}", coutTime.count());
+    SPDLOG_INFO("printf打印耗时: {}", printfTime.count());
+    SPDLOG_INFO("QDebug打印耗时: {}", qDebugTime.count());
+    SPDLOG_INFO("LightLog打印耗时: {}", lightLogTime.count());
 }
 

+ 2 - 0
demo/ftp/widget.h

@@ -24,6 +24,8 @@ private slots:
 
     void on_pBtn_downloadVideo_clicked();
 
+    void on_pBtn_logSpeed_clicked();
+
 private:
     Ui::Widget *ui;
 

+ 7 - 0
demo/ftp/widget.ui

@@ -47,6 +47,13 @@
       </property>
      </widget>
     </item>
+    <item row="1" column="1">
+     <widget class="QPushButton" name="pBtn_logSpeed">
+      <property name="text">
+       <string>日志速度对比</string>
+      </property>
+     </widget>
+    </item>
    </layout>
   </widget>
  </widget>