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
db5c4ed2
Commit
db5c4ed2
authored
Mar 17, 2017
by
Carwyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.同步辅助程序修改
parent
835992d3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
4 deletions
+126
-4
FreemudSyncer/FreemudSyncer.pro
+1
-2
FreemudSyncer/main.cpp
+125
-2
No files found.
FreemudSyncer/FreemudSyncer.pro
View file @
db5c4ed2
...
@@ -4,8 +4,7 @@ QT -= gui
...
@@ -4,8 +4,7 @@ QT -= gui
CONFIG
+=
c
++
11
CONFIG
+=
c
++
11
TARGET
=
FreemudSyncer
TARGET
=
FreemudSyncer
CONFIG
+=
console
CONFIG
+=
app
CONFIG
-=
app_bundle
TEMPLATE
=
app
TEMPLATE
=
app
...
...
FreemudSyncer/main.cpp
View file @
db5c4ed2
#include <QCoreApplication>
#
include
<
QCoreApplication
>
#include <QProcess>
#include <QFile>
#include <QDir>
#include <QDebug>
#include <QDateTime>
#include <QSettings>
void
MessageOutput
(
QtMsgType
type
,
const
QMessageLogContext
&
context
,
const
QString
&
msg
)
{
Q_UNUSED
(
type
);
Q_UNUSED
(
context
);
// 设置输出信息格式
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
()));
file
.
open
(
QIODevice
::
ReadWrite
|
QIODevice
::
Append
);
QTextStream
stream
(
&
file
);
stream
<<
strMessage
<<
"
\r\n
"
;
file
.
flush
();
file
.
close
();
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
if
(
argc
<
2
)
{
qDebug
()
<<
"Usage: FreemudSyncer [App name]"
;
return
0
;
}
QCoreApplication
a
(
argc
,
argv
);
QCoreApplication
a
(
argc
,
argv
);
QString
app
=
argv
[
1
];
// 日志输出
// 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/download/dfilesInfo.txt"
).
arg
(
appDir
));
QFile
resultFile
(
QString
(
"%1/download/updateresult.txt"
).
arg
(
appDir
));
QStringList
dFilesInfo
,
bUpdFiles
;
QString
error
;
bool
updateReault
=
true
;
// 关闭服务
QProcess
::
execute
(
fmscupdPath
,
QStringList
(
"-t"
));
// 开始替换文件
if
(
dInfoFile
.
open
(
QIODevice
::
ReadOnly
))
{
dFilesInfo
=
QString
(
dInfoFile
.
readAll
()).
split
(
","
);
dInfoFile
.
close
();
}
else
{
error
=
QString
(
"open dfilesInfo.txt failed [%1]"
).
arg
(
dInfoFile
.
errorString
());
qDebug
()
<<
error
;
updateReault
=
false
;
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
);
QString
newName
=
QString
(
"%1.bak"
).
arg
(
oldFile
);
qDebug
()
<<
QString
(
"replace 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"
;
}
}
else
{
qDebug
()
<<
"file exists"
;
QFile
(
newName
).
remove
();
if
(
QFile
().
rename
(
oldFile
,
newName
))
{
qDebug
()
<<
"rename successful"
;
}
else
{
qDebug
()
<<
"rename failed"
;
}
}
if
(
QFile
().
copy
(
downloadFile
,
oldFile
))
{
qDebug
()
<<
"copy file successful"
;
}
else
{
error
=
"copy file failed"
;
qDebug
()
<<
error
;
updateReault
=
false
;
// 回滚文件
foreach
(
QString
file
,
bUpdFiles
)
{
qDebug
()
<<
QString
(
"rollback file [%1]"
).
arg
(
file
);
QFile
(
file
).
remove
();
QFile
().
rename
(
QString
(
"%1.bak"
).
arg
(
file
),
file
);
}
break
;
}
bUpdFiles
.
append
(
oldFile
);
}
}
return
a
.
exec
();
end
:
if
(
resultFile
.
open
(
QIODevice
::
WriteOnly
))
{
QByteArray
buf
;
if
(
updateReault
)
{
buf
=
"1"
;
}
else
{
buf
=
QString
(
"0%1"
).
arg
(
error
).
toLatin1
();
}
resultFile
.
write
(
buf
);
resultFile
.
close
();
}
// 启动服务
QProcess
::
startDetached
(
fmscupdPath
,
QStringList
(
fmscupdPath
));
return
0
;
}
}
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