Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmPOS
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaojing.zhang
fmPOS
Commits
63e2e165
Commit
63e2e165
authored
Mar 30, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.oschina.net:kong__mo/fmPOS
parents
7149527b
b7d2e09b
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
290 additions
and
133 deletions
+290
-133
FreemudPOS/FreemudPOS.pro
+1
-1
FreemudPOS/fm_pos_app.cpp
+17
-5
FreemudSyncer/FreemudSyncer.pro
+10
-0
FreemudSyncer/main.cpp
+103
-41
debug/bin/FreemudPOS.ini
+5
-3
fmPos.pro
+2
-1
fmp_home/fmp_he_handlers.cpp
+1
-0
fmp_logger/fmp_logger.cpp
+0
-2
fmp_logger/fmp_logger_p.cpp
+31
-21
fmp_logger/fmp_logger_p.h
+4
-0
fmp_logger/version.h
+1
-1
fmp_manager/fmp_manager.cpp
+11
-4
fmp_manager/version.h
+1
-1
fmp_network/fmp_network.cpp
+10
-26
fmp_network/fmp_network.h
+0
-3
fmp_network/version.h
+1
-1
fmp_settings/fmp_settings_def.h
+3
-2
fmp_settings/version.h
+1
-1
fmp_syncer/fmp_syncer.cpp
+13
-1
fmp_syncer/fmp_syncer.h
+6
-0
fmp_syncer/fmp_syncer_def.h
+5
-1
fmp_syncer/fmp_syncer_i.h
+6
-0
fmp_syncer/fmp_syncer_p.cpp
+52
-16
fmp_syncer/fmp_syncer_p.h
+5
-1
fmp_syncer/version.h
+1
-1
No files found.
FreemudPOS/FreemudPOS.pro
View file @
63e2e165
...
...
@@ -3,7 +3,7 @@ include ("qtservice/src/qtservice.pri")
QT
+=
core
widgets
CONFIG
+=
c
++
11
TARGET
=
fmPos
TARGET
=
FreemudPOS
TEMPLATE
=
app
INCLUDEPATH
+=
$$
PWD
/../
include
/
interface
...
...
FreemudPOS/fm_pos_app.cpp
View file @
63e2e165
...
...
@@ -6,6 +6,14 @@
#include <QDir>
#include <QDirIterator>
#include <qtservice.h>
#ifdef Q_OS_WIN
#include <Windows.h>
//! 命名冲突
#undef StartService
#endif
#include "../fmp_settings/fmp_settings_def.h"
class
FMPService
:
public
QtService
<
QApplication
>
...
...
@@ -18,7 +26,7 @@ public:
QtService
<
QApplication
>
(
argc
,
argv
,
svcname
)
{
createApplication
(
argc
,
argv
);
_setting
=
new
QSettings
(
qApp
->
applicationDirPath
()
+
"/
fmPos
.ini"
,
QSettings
::
IniFormat
);
_setting
=
new
QSettings
(
qApp
->
applicationDirPath
()
+
"/
"
+
qApp
->
applicationName
()
+
"
.ini"
,
QSettings
::
IniFormat
);
_starttype
=
_setting
->
value
(
FMP_INIKEY_SERVICESTARTTYPE
,
0
).
toInt
();
_description
=
_setting
->
value
(
FMP_INIKEY_SERVICEDESC
,
"Freemud POS plugin service"
).
toString
();
_plugin_path
=
_setting
->
value
(
FMP_INIKEY_PLUGINPATH
,
"plugins"
).
toString
();
...
...
@@ -44,6 +52,9 @@ public:
props
[
FMP_PROPKEY_PLUGINPATH
]
=
_plugin_path
;
props
[
FMP_PROPKEY_ENTRY
]
=
_entry_plugin
;
props
[
FMP_PROPKEY_CFG
]
=
_setting
->
fileName
();
#ifdef Q_OS_WIN
props
[
FMP_PROPKEY_PROCID
]
=
QString
::
number
(
GetCurrentProcessId
());
#endif
if
(
FMP_SUCCESS
!=
fmp_manager
->
SetProperties
(
props
)
||
FMP_SUCCESS
!=
fmp_manager
->
StartService
())
{
exit
(
0
);
...
...
@@ -105,10 +116,11 @@ private:
int
main
(
int
argc
,
char
**
argv
)
{
QString
appPath
=
QString
::
fromLocal8Bit
(
argv
[
0
]);
appPath
.
replace
(
"
\\
"
,
"/"
);
appPath
=
appPath
.
section
(
"/"
,
0
,
-
2
);
QSettings
setting
(
appPath
+
"/fmPos.ini"
,
QSettings
::
IniFormat
);
QString
app_path
=
QString
::
fromLocal8Bit
(
argv
[
0
]);
app_path
.
replace
(
"
\\
"
,
"/"
);
QString
app_dir
=
app_path
.
section
(
"/"
,
0
,
-
2
);
QString
app_name
=
app_path
.
section
(
"/"
,
-
1
);
QSettings
setting
(
app_dir
+
"/"
+
app_name
.
replace
(
".exe"
,
".ini"
),
QSettings
::
IniFormat
);
QString
svc_name
=
setting
.
value
(
FMP_INIKEY_SERVICENAME
,
"FMPService"
).
toString
();
FMPService
svc
(
argc
,
argv
,
svc_name
);
...
...
FreemudSyncer/FreemudSyncer.pro
View file @
63e2e165
...
...
@@ -6,6 +6,16 @@ CONFIG += c++11
TARGET
=
FreemudSyncer
CONFIG
+=
app
CONFIG
(
debug
,
debug
|
release
)
{
DESTDIR
=
$$
PWD
/../
debug
/
bin
}
else
{
DESTDIR
=
$$
PWD
/../
release
/
bin
}
win32
{
LIBS
+=
-
lpsapi
}
TEMPLATE
=
app
SOURCES
+=
main
.
cpp
FreemudSyncer/main.cpp
View file @
63e2e165
...
...
@@ -6,6 +6,8 @@
#include <QDateTime>
#include <QSettings>
QString
download_dir
,
deploy_dir
;
void
MessageOutput
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
)
{
Q_UNUSED
(
type
);
Q_UNUSED
(
context
);
...
...
@@ -13,7 +15,7 @@ void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QStr
QString
strDateTime
=
QDateTime
::
currentDateTime
().
toString
(
"yyyy-MM-dd hh:mm:ss.zzz"
);
QString
strMessage
=
QString
(
"%1: %2"
).
arg
(
strDateTime
).
arg
(
msg
);
// 输出信息至文件中(读写、追加形式)
QFile
file
(
QString
(
"%1/
download/porter.log"
).
arg
(
qApp
->
applicationDirPath
()
));
QFile
file
(
QString
(
"%1/
porter.log"
).
arg
(
download_dir
));
file
.
open
(
QIODevice
::
ReadWrite
|
QIODevice
::
Append
);
QTextStream
stream
(
&
file
);
stream
<<
strMessage
<<
"
\r\n
"
;
...
...
@@ -21,31 +23,52 @@ void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QStr
file
.
close
();
}
QString
GetProcessNameByPid
(
int
pid
);
bool
KillProcessByPid
(
int
pid
);
#define FMP_INIKEY_DOWNLOADPATH "Syncer/DownloadPath"
#define FMP_INIKEY_DEPLOYPATH "Syncer/DeployPath"
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
qDebug
()
<<
"Usage: FreemudSyncer [
App name
]"
;
qDebug
()
<<
"Usage: FreemudSyncer [
Process ID
]"
;
return
0
;
}
QCoreApplication
a
(
argc
,
argv
);
QString
app
=
argv
[
1
];
int
instance_pid
=
QString
(
argv
[
1
]).
toInt
();
QString
fmscupdPath
=
GetProcessNameByPid
(
instance_pid
);
QString
app
=
fmscupdPath
.
section
(
"/"
,
-
1
);
#ifdef Q_OS_WIN
QSettings
sets
(
QCoreApplication
::
applicationDirPath
()
+
"/"
+
QString
(
app
).
replace
(
".exe"
,
".ini"
),
QSettings
::
IniFormat
);
#endif
download_dir
=
sets
.
value
(
FMP_INIKEY_DOWNLOADPATH
,
"download"
).
toString
();
deploy_dir
=
sets
.
value
(
FMP_INIKEY_DEPLOYPATH
,
".."
).
toString
();
if
(
QFileInfo
(
deploy_dir
).
isAbsolute
())
{
download_dir
=
deploy_dir
+
"/"
+
download_dir
;
}
else
{
deploy_dir
=
qApp
->
applicationDirPath
()
+
"/"
+
deploy_dir
;
download_dir
=
deploy_dir
+
"/"
+
download_dir
;
}
// 日志输出
// qInstallMessageHandler(MessageOutput);
QDir
().
mkdir
(
download_dir
);
qInstallMessageHandler
(
MessageOutput
);
qDebug
()
<<
"
\r\n\r\n\r\n
"
;
QString
appDir
=
QCoreApplication
::
applicationDirPath
(
);
QString
fmscupdPath
=
QString
(
"%1/%2"
).
arg
(
appDir
).
arg
(
app
);
QFile
dInfoFile
(
QString
(
"%1/d
ownload/dfilesInfo.txt"
).
arg
(
appD
ir
));
QFile
resultFile
(
QString
(
"%1/
download/updateresult.txt"
).
arg
(
appD
ir
));
qDebug
()
<<
QString
(
"Process %1[%2] asks for sync."
).
arg
(
app
).
arg
(
instance_pid
);
QFile
dInfoFile
(
QString
(
"%1/d
filesInfo.txt"
).
arg
(
download_d
ir
));
QFile
resultFile
(
QString
(
"%1/
updateresult.txt"
).
arg
(
download_d
ir
));
QStringList
dFilesInfo
,
bUpdFiles
;
QString
error
;
bool
updateReault
=
true
;
// 关闭服务
QProcess
::
execute
(
fmscupdPath
,
QStringList
(
"-t"
));
// 开始替换文件
if
(
dInfoFile
.
open
(
QIODevice
::
ReadOnly
))
{
...
...
@@ -59,48 +82,51 @@ int main(int argc, char *argv[])
goto
end
;
}
foreach
(
QString
dfile
,
dFilesInfo
)
{
if
(
!
dfile
.
isEmpty
())
{
QString
downloadFile
=
QString
(
"%1/download/%2"
).
arg
(
appDir
,
dfile
);
QString
oldFile
=
QString
(
"%1/%2"
).
arg
(
appDir
,
dfile
);
//! 如果更新包含主程序,则关闭主程序
bool
process_closed
=
false
;
if
(
dFilesInfo
.
contains
(
app
))
{
KillProcessByPid
(
instance_pid
);
process_closed
=
true
;
}
foreach
(
QString
dfile
,
dFilesInfo
)
{
if
(
!
dfile
.
isEmpty
())
{
QString
downloadFile
=
QString
(
"%1/%2"
).
arg
(
download_dir
,
dfile
);
QString
oldFile
=
QString
(
"%1/%2"
).
arg
(
deploy_dir
,
dfile
);
QString
newName
=
QString
(
"%1.bak"
).
arg
(
oldFile
);
qDebug
()
<<
QString
(
"replace file [%1]"
).
arg
(
oldFile
);
if
(
!
QFile
(
oldFile
).
exists
())
{
qDebug
()
<<
QString
(
"checking file [%1]"
).
arg
(
oldFile
);
if
(
!
QFile
(
oldFile
).
exists
())
{
qDebug
()
<<
"file not exists"
;
if
(
QDir
().
mkpath
(
oldFile
.
left
(
oldFile
.
lastIndexOf
(
"/"
))))
{
qDebug
()
<<
"mkdir successful"
;
}
else
{
qDebug
()
<<
"mkdir failed"
;
QDir
parent_dir
(
oldFile
.
section
(
"/"
,
0
,
-
2
));
if
(
!
parent_dir
.
exists
())
{
if
(
parent_dir
.
mkpath
(
parent_dir
.
path
()))
{
qDebug
()
<<
"mkdir successful"
;
}
else
{
qDebug
()
<<
"mkdir failed"
;
}
}
}
else
{
}
else
{
qDebug
()
<<
"file exists"
;
QFile
(
newName
).
remove
();
if
(
QFile
().
rename
(
oldFile
,
newName
))
{
if
(
QFile
().
rename
(
oldFile
,
newName
))
{
qDebug
()
<<
"rename successful"
;
}
else
{
}
else
{
qDebug
()
<<
"rename failed"
;
}
}
if
(
QFile
().
copy
(
downloadFile
,
oldFile
))
{
if
(
QFile
().
copy
(
downloadFile
,
oldFile
))
{
qDebug
()
<<
"copy file successful"
;
}
else
{
}
else
{
error
=
"copy file failed"
;
qDebug
()
<<
error
;
updateReault
=
false
;
// 回滚文件
foreach
(
QString
file
,
bUpdFiles
)
{
foreach
(
QString
file
,
bUpdFiles
)
{
qDebug
()
<<
QString
(
"rollback file [%1]"
).
arg
(
file
);
QFile
(
file
).
remove
();
QFile
().
rename
(
QString
(
"%1.bak"
).
arg
(
file
),
file
);
...
...
@@ -125,7 +151,43 @@ end:
resultFile
.
write
(
buf
);
resultFile
.
close
();
}
// 启动服务
QProcess
::
startDetached
(
fmscupdPath
,
QStringList
(
fmscupdPath
));
if
(
process_closed
)
{
// 启动服务
QProcess
::
startDetached
(
fmscupdPath
,
QStringList
());
}
return
0
;
}
#ifdef Q_OS_WIN
#include <Windows.h>
#include <Psapi.h>
#endif
QString
GetProcessNameByPid
(
int
pid
)
{
QString
proc_name
;
#ifdef Q_OS_WIN
HANDLE
hProcess
=
OpenProcess
(
PROCESS_ALL_ACCESS
,
false
,
pid
);
WCHAR
module
[
MAX_PATH
]
=
{
0
};
GetModuleFileNameEx
(
hProcess
,
NULL
,
module
,
MAX_PATH
);
proc_name
=
QString
::
fromWCharArray
(
module
);
proc_name
=
proc_name
.
replace
(
"
\\
"
,
"/"
);
#endif
return
proc_name
;
}
bool
KillProcessByPid
(
int
pid
)
{
bool
killed
=
false
;
#ifdef Q_OS_WIN
HANDLE
hProcess
=
OpenProcess
(
PROCESS_ALL_ACCESS
,
false
,
pid
);
killed
=
(
TerminateProcess
(
hProcess
,
0
)
==
TRUE
);
#endif
return
killed
;
}
debug/bin/
fmPos
.ini
→
debug/bin/
FreemudPOS
.ini
View file @
63e2e165
...
...
@@ -9,7 +9,7 @@ Path=../plugins
EntryService
=
com.fmp.home
[Log]
Path
=
log
/testlog
Path
=
log
Size
=
1
;0:关闭 1:错误 2:警告 3:信息 4:调试
Level
=
0
...
...
@@ -29,4 +29,6 @@ Animation=1
[Syncer]
Interval
=
3
TaskUrl
=
http://192.168.110.150:8080/api/fork/checkupdate
\ No newline at end of file
TaskUrl
=
http://192.168.110.150:8080/api/fork/checkupdate
DeployPath
=
..
DownloadPath
=
download
\ No newline at end of file
fmPos.pro
View file @
63e2e165
...
...
@@ -9,6 +9,7 @@ SUBDIRS += fmp_manager \
fmp_syncer
\
fmp_epay
\
fmp_home
\
FreemudPOS
FreemudPOS
\
FreemudSyncer
CONFIG
+=
ordered
fmp_home/fmp_he_handlers.cpp
View file @
63e2e165
...
...
@@ -14,6 +14,7 @@ FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPHome *home)
void
FMPStartEventHandler
::
handleEvent
(
const
ctkEvent
&
event
)
{
qDebug
()
<<
"==========="
;
if
(
_home
)
{
QString
ack_topic
=
event
.
getTopic
();
//! com/fmp/services/REQ_START/id
...
...
fmp_logger/fmp_logger.cpp
View file @
63e2e165
...
...
@@ -80,8 +80,6 @@ void FMPLogger::SetPath(const QString &path)
QIODevice
*
FMPLogger
::
GetIODevice
()
{
d_func
()
->
_KeepFileSize
();
return
_file
;
}
...
...
fmp_logger/fmp_logger_p.cpp
View file @
63e2e165
...
...
@@ -10,12 +10,15 @@
FMPLoggerPrivate
::
FMPLoggerPrivate
(
FMPLogger
*
q
,
ctkPluginContext
*
ctx
)
:
q_ptr
(
q
),
_ctx
(
ctx
),
_inited
(
false
)
_inited
(
false
),
_file_index
(
0
)
{
_lvlmap
[
FMPLogger
::
LOG_DEBUG
]
=
"dbg"
;
_lvlmap
[
FMPLogger
::
LOG_INFO
]
=
"info"
;
_lvlmap
[
FMPLogger
::
LOG_WARNING
]
=
"warn"
;
_lvlmap
[
FMPLogger
::
LOG_ERROR
]
=
"err"
;
_lvlmap
[
FMPLogger
::
LOG_ERROR
]
=
"error"
;
_log_date
=
QDateTime
::
currentDateTime
();
}
int
FMPLoggerPrivate
::
Init
()
...
...
@@ -24,10 +27,11 @@ int FMPLoggerPrivate::Init()
Q_Q
(
FMPLogger
);
QString
filename
=
_NewFileName
();
q
->
_file
=
new
QFile
(
filename
);
q
->
_file
->
open
(
QFile
::
WriteOnly
);
if
(
q
->
_level
>
0
)
{
QString
filename
=
_NewFileName
();
q
->
_file
=
new
QFile
(
filename
);
q
->
_file
->
open
(
QFile
::
Append
);
}
_inited
=
true
;
return
FMP_SUCCESS
;
}
...
...
@@ -95,11 +99,7 @@ void FMPLoggerPrivate::Log(short level, const QString &msg, const char* file, co
Q_Q
(
FMPLogger
);
if
(
level
>
q
->
_level
)
{
if
(
q
->
_file
->
size
()
>=
(
q
->
_max_size
*
1024
*
1024
))
{
q
->
_file
->
close
();
q
->
_file
->
setFileName
(
_NewFileName
());
q
->
_file
->
open
(
QFile
::
WriteOnly
);
}
_KeepFileSize
();
FMPLogStream
(
level
,
file
,
func
,
line
,
q
->
_file
)
<<
msg
;
}
else
{
...
...
@@ -109,7 +109,14 @@ void FMPLoggerPrivate::Log(short level, const QString &msg, const char* file, co
QString
FMPLoggerPrivate
::
_NewFileName
()
{
QString
file_time
=
QDateTime
::
currentDateTime
().
toString
(
"yyMMddhhmmss"
);
if
(
_log_date
.
date
()
<
QDateTime
::
currentDateTime
().
date
())
{
//! 日志记录重置
_file_index
=
0
;
_log_date
=
QDateTime
::
currentDateTime
();
}
QString
file_index
=
QString
::
number
(
++
_file_index
);
Q_Q
(
FMPLogger
);
QString
log_path
=
GetLogPath
();
QDir
log_dir
(
log_path
);
...
...
@@ -121,7 +128,7 @@ QString FMPLoggerPrivate::_NewFileName()
_FMP_INFO
<<
"Create log dir"
<<
log_path
<<
"failed!"
;
}
}
return
q
->
_path
+
"/"
+
_lvlmap
[
q
->
_level
]
+
"_"
+
file_
time
+
".log"
;
return
q
->
_path
+
"/"
+
_lvlmap
[
q
->
_level
]
+
"_"
+
file_
index
+
".log"
;
}
bool
FMPLoggerPrivate
::
_SetValue
(
const
QString
&
key
,
QVariant
v
)
...
...
@@ -156,13 +163,16 @@ QVariant FMPLoggerPrivate::_GetValue(const QString &key, QVariant default_val)
void
FMPLoggerPrivate
::
_KeepFileSize
()
{
Q_Q
(
FMPLogger
);
qint64
file_sz
=
q
->
_file
->
size
();
if
(
file_sz
>=
(
q
->
_max_size
*
1024
*
1024
))
{
QString
new_file_name
=
_NewFileName
();
FMP_INFO
(
q
)
<<
"Current log file size:"
<<
file_sz
<<
"reaches max value"
;
FMP_INFO
(
q
)
<<
"New log file:"
<<
new_file_name
;
q
->
_file
->
close
();
q
->
_file
->
setFileName
(
new_file_name
);
q
->
_file
->
open
(
QFile
::
WriteOnly
);
if
(
q
->
_level
>
0
)
{
qint64
file_sz
=
q
->
_file
->
size
();
if
(
file_sz
>=
(
q
->
_max_size
*
1024
*
1024
))
{
QString
new_file_name
=
_NewFileName
();
FMP_INFO
(
q
)
<<
"Current log file size:"
<<
file_sz
<<
"reaches max value"
;
FMP_INFO
(
q
)
<<
"New log file:"
<<
new_file_name
;
q
->
_file
->
close
();
q
->
_file
->
setFileName
(
new_file_name
);
q
->
_file
->
open
(
QFile
::
Append
);
}
}
}
fmp_logger/fmp_logger_p.h
View file @
63e2e165
...
...
@@ -30,6 +30,10 @@ public:
FMPLogger
*
q_ptr
;
ctkPluginContext
*
_ctx
;
QMap
<
short
,
QString
>
_lvlmap
;
int
_file_index
;
QDateTime
_log_date
;
};
#define _FMP_INFO FMPNullLogStream(FMPLogger::LOG_INFO, __FILE__, __FUNCTION__, __LINE__)
...
...
fmp_logger/version.h
View file @
63e2e165
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD
10
#define VER_BUILD
28
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_manager/fmp_manager.cpp
View file @
63e2e165
...
...
@@ -213,12 +213,12 @@ QFileInfo FMPluginManager::GetPluginInfo(const QString &plugin_name, const QStri
plugin_file_name
.
replace
(
"."
,
"_"
);
QStringList
filters
;
#ifdef Q_OS_WIN
filters
<<
plugin_file_name
+
"*"
+
".dll"
;
filters
<<
"*"
+
plugin_file_name
+
"*"
+
".dll"
;
#else
# ifdef Q_OS_LINUX
filters
<<
plugin_file_name
+
"*"
+
".so"
;
filters
<<
"*"
+
plugin_file_name
+
"*"
+
".so"
;
# else
filters
<<
plugin_file_name
+
"*"
+
".dylib"
;
filters
<<
"*"
+
plugin_file_name
+
"*"
+
".dylib"
;
# endif
#endif
QDirIterator
dir_iter
(
qApp
->
applicationDirPath
()
+
"/"
+
_fw_props
[
FMP_PROPKEY_PLUGINPATH
].
toString
(),
filters
,
QDir
::
Files
);
...
...
@@ -230,7 +230,14 @@ QFileInfo FMPluginManager::GetPluginInfo(const QString &plugin_name, const QStri
QString
file_basename
=
file_info
.
completeBaseName
();
if
(
file_basename
.
startsWith
(
"lib"
))
file_basename
=
file_basename
.
mid
(
3
);
QString
tmp_ver
=
file_basename
.
section
(
plugin_file_name
,
1
,
1
).
replace
(
"_"
,
""
);
if
(
plugin_version
.
isEmpty
()
||
plugin_version
<
tmp_ver
)
{
if
(
plugin_version
.
isEmpty
())
{
plugin_version
=
tmp_ver
;
plugin_file_info
=
file_info
;
}
else
if
(
plugin_version
<
tmp_ver
)
{
//! 删除旧版本
QFile
::
remove
(
plugin_file_info
.
absoluteFilePath
());
plugin_version
=
tmp_ver
;
plugin_file_info
=
file_info
;
}
...
...
fmp_manager/version.h
View file @
63e2e165
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD
10
#define VER_BUILD
28
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_network/fmp_network.cpp
View file @
63e2e165
...
...
@@ -74,7 +74,6 @@ FMPHttpReplyPointer FMPNetworkPrivate::HttpGet(const FMPHttpRequest &r)
req_timer
[
net_manager
]
=
timer
;
QNetworkReply
*
net_reply
=
net_manager
->
get
(
req
);
connect
(
net_reply
,
SIGNAL
(
error
(
QNetworkReply
::
NetworkError
)),
SLOT
(
OnRequestError
(
int
)));
connect
(
timer
,
SIGNAL
(
timeout
()),
SLOT
(
OnRequestTimeout
()));
timer
->
start
(
r
.
timeout
);
...
...
@@ -106,7 +105,6 @@ FMPHttpReplyPointer FMPNetworkPrivate::HttpPost(const FMPHttpRequest &req, const
req_timer
[
net_manager
]
=
timer
;
QNetworkReply
*
net_reply
=
net_manager
->
post
(
request
,
data
);
connect
(
net_reply
,
SIGNAL
(
error
(
QNetworkReply
::
NetworkError
)),
SLOT
(
OnRequestError
(
QNetworkReply
::
NetworkError
)));
connect
(
timer
,
SIGNAL
(
timeout
()),
SLOT
(
OnRequestTimeout
()));
timer
->
start
(
req
.
timeout
);
...
...
@@ -124,31 +122,17 @@ void FMPNetworkPrivate::OnRequestFinished(QNetworkReply *reply)
{
QNetworkAccessManager
*
net_manager
=
reply
->
manager
();
FMPSockReplyPointer
fmp_reply
=
req_map
[
net_manager
];
fmp_reply
->
SetResponse
(
reply
->
readAll
());
fmp_reply
->
SetError
(
reply
->
error
());
fmp_reply
->
Finish
(
fmp_reply
);
req_map
.
take
(
net_manager
);
QTimer
*
timer
=
req_timer
.
take
(
net_manager
);
timer
->
deleteLater
();
net_manager
->
deleteLater
();
}
void
FMPNetworkPrivate
::
OnRequestError
(
QNetworkReply
::
NetworkError
err
)
{
QNetworkReply
*
reply
=
qobject_cast
<
QNetworkReply
*>
(
sender
());
if
(
req_map
.
contains
(
net_manager
))
{
FMPSockReplyPointer
fmp_reply
=
req_map
[
net_manager
];
fmp_reply
->
SetResponse
(
reply
->
readAll
());
fmp_reply
->
SetError
(
reply
->
error
());
fmp_reply
->
Finish
(
fmp_reply
);
QNetworkAccessManager
*
net_manager
=
reply
->
manager
();
FMPSockReplyPointer
fmp_reply
=
req_map
[
net_manager
];
fmp_reply
->
SetError
(
err
);
fmp_reply
->
SetErrorString
(
"Request timeout"
);
fmp_reply
->
Finish
(
fmp_reply
);
req_map
.
take
(
net_manager
);
QTimer
*
timer
=
req_timer
.
take
(
net_manager
);
timer
->
deleteLater
();
net_manager
->
deleteLater
();
req_map
.
take
(
net_manager
);
QTimer
*
timer
=
req_timer
.
take
(
net_manager
);
timer
->
deleteLater
();
net_manager
->
deleteLater
();
}
}
void
FMPNetworkPrivate
::
OnRequestTimeout
()
...
...
fmp_network/fmp_network.h
View file @
63e2e165
...
...
@@ -3,8 +3,6 @@
#include <QObject>
#include "fmp_network_i.h"
#include <QNetworkReply>
#include <QQueue>
class
QTimer
;
class
FMPNetworkPrivate
;
...
...
@@ -61,7 +59,6 @@ public:
public
slots
:
void
OnRequestFinished
(
QNetworkReply
*
reply
);
void
OnRequestError
(
QNetworkReply
::
NetworkError
err
);
void
OnRequestTimeout
();
protected
:
...
...
fmp_network/version.h
View file @
63e2e165
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD
13
#define VER_BUILD
28
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_settings/fmp_settings_def.h
View file @
63e2e165
...
...
@@ -5,9 +5,10 @@
#define FMP_PROPKEY_PLUGINPATH "FMPPath"
#define FMP_PROPKEY_CFG "FMPConfig"
#define FMP_PROPKEY_ENTRY "FMPEntry"
#define FMP_PROPKEY_PID "PMPid"
#define FMP_PROPKEY_PID_LIST "FMPidList"
#define FMP_PROPKEY_PID "PMP
P
id"
#define FMP_PROPKEY_PID_LIST "FMP
P
idList"
#define FMP_PROPKEY_AGREED "FMPAgreed"
#define FMP_PROPKEY_PROCID "FMPProcId"
//! 配置文件 Key
#define FMP_INIKEY_SERVICENAME "Service/Name"
...
...
fmp_settings/version.h
View file @
63e2e165
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD
13
#define VER_BUILD
28
//! Convert version numbers to string
#define _STR(S) #S
...
...
fmp_syncer/fmp_syncer.cpp
View file @
63e2e165
...
...
@@ -12,7 +12,9 @@ FMPSyncer::FMPSyncer(ctkPluginContext *ctx)
_sync_interval
(
d_ptr
->
GetSyncInterval
()),
_req_timeout
(
d_ptr
->
GetRequestTimeout
()),
_task_url
(
d_ptr
->
GetTaskUrl
()),
_task_report_url
(
d_ptr
->
GetTaskReportUrl
())
_task_report_url
(
d_ptr
->
GetTaskReportUrl
()),
_deploy_path
(
d_ptr
->
GetDeployPath
()),
_download_path
(
d_ptr
->
GetDownloadPath
())
{
StartService
();
...
...
@@ -65,3 +67,13 @@ void FMPSyncer::SetTaskReportUrl(const QString &url)
{
d_func
()
->
SetTaskReportUrl
(
url
);
}
void
FMPSyncer
::
SetDownloadPath
(
const
QString
&
path
)
{
d_func
()
->
SetDownloadPath
(
path
);
}
void
FMPSyncer
::
SetDeployPath
(
const
QString
&
path
)
{
d_func
()
->
SetDeployPath
(
path
);
}
fmp_syncer/fmp_syncer.h
View file @
63e2e165
...
...
@@ -31,6 +31,8 @@ public:
int
GetSyncInterval
()
const
{
return
_sync_interval
;
}
QString
GetTaskUrl
()
const
{
return
_task_url
;
}
QString
GetTaskReportUrl
()
const
{
return
_task_report_url
;
}
QString
GetDownloadPath
()
const
{
return
_download_path
;
}
QString
GetDeployPath
()
const
{
return
_deploy_path
;
}
void
SetStoreId
(
const
QString
&
id
);
void
SetPosId
(
const
QString
&
id
);
...
...
@@ -38,6 +40,8 @@ public:
void
SetSyncInterval
(
int
ms
);
void
SetTaskUrl
(
const
QString
&
url
);
void
SetTaskReportUrl
(
const
QString
&
url
);
void
SetDownloadPath
(
const
QString
&
path
);
void
SetDeployPath
(
const
QString
&
path
);
private
:
FMPSyncerPrivate
*
d_ptr
;
...
...
@@ -51,6 +55,8 @@ private:
QString
_task_report_url
;
QString
_upload_url
;
QString
_upload_report_url
;
QString
_download_path
;
QString
_deploy_path
;
};
#endif // FMP_SYNCER_H
fmp_syncer/fmp_syncer_def.h
View file @
63e2e165
...
...
@@ -41,11 +41,15 @@
#define FMP_INIKEY_SYNCINTERVAL "Syncer/Interval"
#define FMP_INIKEY_SYNCTASKURL "Syncer/TaskUrl"
#define FMP_INIKEY_SYNCTASKRPTURL "Syncer/TaskReportUrl"
#define FMP_INIKEY_DOWNLOADPATH "Syncer/DownloadPath"
#define FMP_INIKEY_DEPLOYPATH "Syncer/DeployPath"
#define FMP_INIKEY_SYNCHELPER "Syncer/FreemudSyncer"
#define FMPSYNC_DEFAULT_INTERVAL 60
#define FMPSYNC_DEFAULT_TASKURL "http://192.168.110.150:8080/api/fork/checkupdate"
#define FMPSYNC_DEFAULT_TASKRPTURL "http://192.168.110.150:8080/api/fork/PosPlanState"
#define FMPSYNC_DEFAULT_DOWNLOADPATH "download"
#define FMPSYNC_DEFAULT_DEPLOYPATH ".."
#define FMPNW_DEFAULT_TIMEOUT 30
#define FMPCOMMON_DEFAULT_PARTNERID "1101"
#define FMPCOMMON_DEFAULT_STOREID "fm99999"
...
...
fmp_syncer/fmp_syncer_i.h
View file @
63e2e165
...
...
@@ -51,6 +51,12 @@ public:
virtual
QString
GetTaskReportUrl
()
const
=
0
;
virtual
void
SetTaskReportUrl
(
const
QString
&
url
)
=
0
;
virtual
QString
GetDeployPath
()
const
=
0
;
virtual
void
SetDeployPath
(
const
QString
&
url
)
=
0
;
virtual
QString
GetDownloadPath
()
const
=
0
;
virtual
void
SetDownloadPath
(
const
QString
&
path
)
=
0
;
// /**
// * @brief GetUploadReportUrl
// * 获取汇报上传结果的URL
...
...
fmp_syncer/fmp_syncer_p.cpp
View file @
63e2e165
...
...
@@ -14,6 +14,7 @@
#include <QTimer>
#include <QEventLoop>
#include <QCryptographicHash>
#include <QProcess>
#include "JlCompress.h"
FMPSyncerPrivate
::
FMPSyncerPrivate
(
FMPSyncer
*
q
)
...
...
@@ -91,6 +92,16 @@ QString FMPSyncerPrivate::GetTaskReportUrl()
return
_GetValue
(
FMP_INIKEY_SYNCTASKRPTURL
,
FMPSYNC_DEFAULT_TASKRPTURL
).
toString
();
}
QString
FMPSyncerPrivate
::
GetDownloadPath
()
{
return
_GetValue
(
FMP_INIKEY_DOWNLOADPATH
,
FMPSYNC_DEFAULT_DOWNLOADPATH
).
toString
();
}
QString
FMPSyncerPrivate
::
GetDeployPath
()
{
return
_GetValue
(
FMP_INIKEY_DEPLOYPATH
,
FMPSYNC_DEFAULT_DEPLOYPATH
).
toString
();
}
void
FMPSyncerPrivate
::
SetStoreId
(
const
QString
&
id
)
{
_SetValue
(
FMP_INIKEY_STOREID
,
id
);
...
...
@@ -121,6 +132,16 @@ void FMPSyncerPrivate::SetTaskReportUrl(const QString &url)
_SetValue
(
FMP_INIKEY_SYNCTASKRPTURL
,
url
);
}
void
FMPSyncerPrivate
::
SetDownloadPath
(
const
QString
&
path
)
{
_SetValue
(
FMP_INIKEY_DOWNLOADPATH
,
path
);
}
void
FMPSyncerPrivate
::
SetDeployPath
(
const
QString
&
path
)
{
_SetValue
(
FMP_INIKEY_DEPLOYPATH
,
path
);
}
QVariant
FMPSyncerPrivate
::
_GetValue
(
const
QString
&
k
,
QVariant
default_val
)
{
if
(
!
_sets
)
{
...
...
@@ -159,7 +180,12 @@ bool FMPSyncerPrivate::_SetValue(const QString &k, QVariant val)
void
FMPSyncerPrivate
::
run
()
{
Q_Q
(
FMPSyncer
);
_app_dir
=
QApplication
::
applicationDirPath
();
if
(
QFileInfo
(
q
->
_deploy_path
).
isAbsolute
())
{
_deploy_dir
=
q
->
_deploy_path
;
}
else
{
_deploy_dir
=
QApplication
::
applicationDirPath
()
+
"/"
+
q
->
_deploy_path
;
}
int
sync_interval
=
q
->
_sync_interval
;
QString
task_id
;
...
...
@@ -182,6 +208,8 @@ void FMPSyncerPrivate::run()
#ifdef QT_DEBUG
//!TEST
task_json
[
"NeedUpdate"
]
=
"yes"
;
task_json
[
"UpdatePath"
]
=
"http://192.168.110.150:8080/UpgradeFiles/1101"
;
task_json
.
insert
(
"NeedUpload"
,
"yes"
);
task_json
.
insert
(
"UploadFiles"
,
"img/yb.jpg|img/dlb.jpg"
);
//!TEST
...
...
@@ -213,14 +241,14 @@ void FMPSyncerPrivate::run()
FMP_INFO
(
_logger
)
<<
QString
(
"Download [%1] files successful"
).
arg
(
latest_files
.
count
());
//! 记录升级任务编号
QFile
planIdFile
(
QString
(
"%1/
download/planid.txt"
).
arg
(
_app_dir
));
QFile
planIdFile
(
QString
(
"%1/
%2/planid.txt"
).
arg
(
_deploy_dir
).
arg
(
q
->
_download_path
));
if
(
planIdFile
.
open
(
QIODevice
::
WriteOnly
))
{
planIdFile
.
write
(
QString
::
number
(
task_json
[
FMP_JSONKEY_PLANID
].
toInt
()).
toLatin1
());
planIdFile
.
close
();
}
//! 将需要替换的文件写入
./download/
dfilesInfo.txt
QFile
file
(
QString
(
"%1/
download/dfilesInfo.txt"
).
arg
(
_app_dir
));
//! 将需要替换的文件写入
dfilesInfo.txt
QFile
file
(
QString
(
"%1/
%2/dfilesInfo.txt"
).
arg
(
_deploy_dir
).
arg
(
q
->
_download_path
));
if
(
file
.
open
(
QIODevice
::
WriteOnly
))
{
QTextStream
stream
(
&
file
);
foreach
(
QString
f
,
downloaded_files
)
{
...
...
@@ -229,9 +257,10 @@ void FMPSyncerPrivate::run()
file
.
close
();
//! 通知升级已准备就绪
FMP_INFO
(
_logger
)
<<
"Upgrade ready"
;
emit
UpgradeReady
();
QString
sync_helper
=
_GetValue
(
FMP_INIKEY_SYNCHELPER
,
"FreemudSyncer"
).
toString
();
QStringList
params
;
params
<<
q
->
_ctx
->
getProperty
(
FMP_PROPKEY_PROCID
).
toString
();
QProcess
::
startDetached
(
sync_helper
,
params
);
}
}
else
{
...
...
@@ -250,15 +279,16 @@ void FMPSyncerPrivate::run()
void
FMPSyncerPrivate
::
ReportTask
(
const
QString
&
tid
,
const
QString
&
msg
,
const
QString
&
state
)
{
QString
task_id
,
task_msg
,
task_state
;
QFile
resultFile
(
QString
(
"%1/download/updateresult.txt"
).
arg
(
_app_dir
));
Q_Q
(
FMPSyncer
);
QFile
resultFile
(
QString
(
"%1/%2/updateresult.txt"
).
arg
(
_deploy_dir
).
arg
(
q
->
_download_path
));
if
(
resultFile
.
exists
()
&&
tid
.
isEmpty
())
{
if
(
tid
.
isEmpty
())
{
QFile
file
(
QString
(
"%1/
download/planid.txt"
).
arg
(
_app_dir
));
QFile
file
(
QString
(
"%1/
%2/planid.txt"
).
arg
(
_deploy_dir
).
arg
(
q
->
_download_path
));
if
(
file
.
open
(
QIODevice
::
ReadOnly
))
{
task_id
=
QString
(
file
.
readAll
());
file
.
close
();
}
file
.
setFileName
(
QString
(
"%1/
download/updateresult.txt"
).
arg
(
_app_dir
));
file
.
setFileName
(
QString
(
"%1/
%2/updateresult.txt"
).
arg
(
_deploy_dir
).
arg
(
q
->
_download_path
));
if
(
file
.
open
(
QIODevice
::
ReadOnly
))
{
QString
readStr
=
file
.
readAll
();
task_state
=
readStr
.
mid
(
0
,
1
);
...
...
@@ -351,7 +381,7 @@ bool FMPSyncerPrivate::UploadFiles(const QStringList &files)
bool
upload_success
=
false
;
QStringList
uploaded_file
;
foreach
(
QString
f
,
files
)
{
QString
file_path
=
QString
(
"%1/%2"
).
arg
(
_
app
_dir
,
f
);
QString
file_path
=
QString
(
"%1/%2"
).
arg
(
_
deploy
_dir
,
f
);
if
(
!
JlCompress
::
compressFile
(
file_path
+
".zip"
,
file_path
))
{
FMP_ERROR
(
_logger
)
<<
QString
(
"Compress file[%1] failed"
).
arg
(
file_path
);
continue
;
...
...
@@ -424,7 +454,7 @@ bool FMPSyncerPrivate::RetainLatestFiles(const QMap<QString, QString> &all_files
{
QStringList
keys
=
all_files
.
keys
();
foreach
(
QString
k
,
keys
)
{
QFile
file
(
QString
(
"%1/%2"
).
arg
(
_
app
_dir
,
k
));
QFile
file
(
QString
(
"%1/%2"
).
arg
(
_
deploy
_dir
,
k
));
if
(
file
.
open
(
QFile
::
ReadOnly
))
{
QString
local_md5
=
QCryptographicHash
::
hash
(
file
.
readAll
(),
QCryptographicHash
::
Md5
).
toHex
();
if
(
local_md5
==
all_files
[
k
])
{
...
...
@@ -448,7 +478,7 @@ QString FMPSyncerPrivate::GetFileMd5(const QString &file_path)
file
.
close
();
}
else
{
FMP_
ERROR
(
_logger
)
<<
"Failed open file"
<<
file_path
<<
file
.
errorString
();
FMP_
INFO
(
_logger
)
<<
"Failed open file"
<<
file_path
<<
file
.
errorString
();
}
return
md5
;
...
...
@@ -458,16 +488,22 @@ QStringList FMPSyncerPrivate::DownloadFiles(const QString &url, const QMap<QStri
{
QStringList
keys
=
files
.
keys
();
QStringList
downloaded_files
;
Q_Q
(
FMPSyncer
);
foreach
(
QString
k
,
keys
)
{
QString
download_url
=
QString
(
"%1/%2.zip"
).
arg
(
url
,
k
);
QString
save_path
=
QString
(
"%1/
download/%2.zip"
).
arg
(
_app_dir
,
k
);
QString
save_path
=
QString
(
"%1/
%2/%3.zip"
).
arg
(
_deploy_dir
,
q
->
_download_path
,
k
);
FMP_INFO
(
_logger
)
<<
QString
(
"Start downloading file [%1]"
).
arg
(
download_url
);
//! 下载之前先检测文件是否下载过
if
(
GetFileMd5
(
save_path
.
left
(
save_path
.
lastIndexOf
(
"."
)))
==
files
[
k
])
{
QString
local_md5
=
GetFileMd5
(
save_path
.
left
(
save_path
.
lastIndexOf
(
"."
)));
if
(
local_md5
==
files
[
k
])
{
FMP_INFO
(
_logger
)
<<
"file exists"
;
downloaded_files
<<
k
;
continue
;
}
else
{
FMP_WARN
(
_logger
)
<<
"Md5 not match, local:"
<<
local_md5
<<
"remote:"
<<
files
[
k
];
}
//! 下载文件
QDir
().
mkpath
(
save_path
.
left
(
save_path
.
lastIndexOf
(
"/"
)));
...
...
@@ -488,7 +524,7 @@ QStringList FMPSyncerPrivate::DownloadFiles(const QString &url, const QMap<QStri
JlCompress
::
extractDir
(
save_path
,
save_path
.
left
(
save_path
.
lastIndexOf
(
"/"
)));
//! 检查下载的文件MD5是否正确
QString
local_md5
=
GetFileMd5
(
save_path
.
left
(
save_path
.
lastIndexOf
(
"."
)));
local_md5
=
GetFileMd5
(
save_path
.
left
(
save_path
.
lastIndexOf
(
"."
)));
if
(
local_md5
!=
files
[
k
])
{
FMP_ERROR
(
_logger
)
<<
"Md5 not match, local:"
<<
local_md5
<<
"remote:"
<<
files
[
k
];
}
...
...
fmp_syncer/fmp_syncer_p.h
View file @
63e2e165
...
...
@@ -35,6 +35,8 @@ public:
int
GetSyncInterval
();
QString
GetTaskUrl
();
QString
GetTaskReportUrl
();
QString
GetDownloadPath
();
QString
GetDeployPath
();
void
SetStoreId
(
const
QString
&
id
);
void
SetPosId
(
const
QString
&
id
);
...
...
@@ -43,6 +45,8 @@ public:
void
SetSyncInterval
(
int
sec
);
void
SetTaskUrl
(
const
QString
&
url
);
void
SetTaskReportUrl
(
const
QString
&
url
);
void
SetDownloadPath
(
const
QString
&
path
);
void
SetDeployPath
(
const
QString
&
path
);
private
:
QVariant
_GetValue
(
const
QString
&
k
,
QVariant
default_val
);
...
...
@@ -128,7 +132,7 @@ public:
FMPSettingsInterface
*
_sets
;
FMPNetworkInterface
*
_nw
;
QString
_
app
_dir
;
//! 记录程序所在的目录
QString
_
deploy
_dir
;
//! 记录程序所在的目录
};
#endif // FMP_SYNCER_P_H
fmp_syncer/version.h
View file @
63e2e165
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_BUILD
13
#define VER_BUILD
28
//! Convert version numbers to string
#define _STR(S) #S
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment