فهرست منبع

change include/ivversion.h. add get git version from .git folder, and showversion use this code.

yuchuli 3 سال پیش
والد
کامیت
55cb5c88bc
2فایلهای تغییر یافته به همراه52 افزوده شده و 1 حذف شده
  1. 50 1
      include/ivversion.h
  2. 2 0
      src/driver/driver_ntrip_client/main.cpp

+ 50 - 1
include/ivversion.h

@@ -1,9 +1,58 @@
+#ifndef IVVERSION_H
+#define IVVERSION_H
 
 #define VERSION "1.1.0-develop"
 
 
 #include <iostream>
+#include <stdio.h>
+#include <fstream>
+#include <string.h>
 
-#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<VERSION<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
+#include <QFile>
 
+std::string getgitversion()
+{
+    std::string strrtn;
+    bool bfileok = false;
+    char strpath[256];
+    char strtem[256];
+    char strbase[256];
+    snprintf(strbase,256,"./.git/refs/heads/master");
+    snprintf(strtem,256,"./.");
+    int i;
+    for(i=0;i<5;i++)
+    {
+        strncpy(strpath,strtem,256);
+        int j;
+        for(j=0;j<i;j++)strncat(strpath,strtem,256);
+        strncat(strpath,strbase,256);
+        std::ifstream f(strpath);
+        if(f.good())
+        {
+            char strdata[256];
+            f.read(strdata,256);
+            if(f.gcount()>0)strrtn.append(strdata,f.gcount());
 
+            //        std::cout<<"file ok"<<"size is "<<f.gcount()<<std::endl;
+            bfileok = true;
+            f.close();
+            break;
+        }
+        else
+        {
+            //        std::cout<<" not ok"<<std::endl;
+        }
+    }
+    if(bfileok == false)
+    {
+        strrtn = VERSION;
+    }
+    return strrtn;
+}
+
+//#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<VERSION<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
+
+#define showversion(modulename) do{std::cout<<"ADC IV Version:"<<getgitversion()<<" | Module name: "<<modulename<<" | Build Time: "<<__DATE__<<" "<<__TIME__<<std::endl;}while(0);
+
+#endif

+ 2 - 0
src/driver/driver_ntrip_client/main.cpp

@@ -3,9 +3,11 @@
 #include "ntrip_client.h"
 
 #include "xmlparam.h"
+#include "ivversion.h"
 
 int main(int argc, char *argv[])
 {
+    showversion("driver_ntrip_client");
     QCoreApplication a(argc, argv);
 
     std::string  strip,strport,strmountpoint,strusername,strpassword,strdevname,strbuadrate;