Skip to content

Commit

Permalink
完善自动升级模块,修复服务器版本号小于开发版本号时仍然更新的bug; 添加Document 目录,用于开发者记录和交流
Browse files Browse the repository at this point in the history
  • Loading branch information
BensonLaur committed Jul 10, 2017
1 parent c57be6c commit 0b2baa5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
40 changes: 35 additions & 5 deletions BesLyric/AutoUpdateThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ DWORD WINAPI AutoUpdateThread::ThreadProc(LPVOID pParam)
{
AutoUpdateThread* pThread = static_cast<AutoUpdateThread*>(pParam);

//启动之后15秒才开始更新。
//发布新版本时,即在Realease 下,会自动更新,为了编译后不立刻更新导致版本被自动被替换成较低版本,设置15秒延时,在15秒内关闭则不会被自动替换
Sleep(15000);

#if _KEEP_UPDATE == 0
pThread->m_bKeepUpdate = false;
#endif
Expand Down Expand Up @@ -122,7 +118,7 @@ bool AutoUpdateThread::AutoUpdate()
}
}

if(VERSION_NUMBER == strVersion) // 版本一致
if(VersionCompare(VERSION_NUMBER, strVersion) >= 0 ) // 版本一致 或者 当前版本大于服务器版本(处于开发状态)
{
m_bHasUpdate = true;
return true;
Expand Down Expand Up @@ -182,6 +178,38 @@ bool AutoUpdateThread::AutoUpdate()
return true;
}

//比较2个字符串版本号的大小,
int AutoUpdateThread::VersionCompare(const SStringW v1, const SStringW v2)
{
int nMainNum1 = 0, nSubNum1= 0, nModifidNum1= 0;
int nMainNum2 = 0, nSubNum2= 0, nModifidNum2= 0;
swscanf(v1,L"%d.%d.%d",&nMainNum1, &nSubNum1, &nModifidNum1);
swscanf(v2,L"%d.%d.%d",&nMainNum2, &nSubNum2, &nModifidNum2);

if(nMainNum1 > nMainNum2)
return 1;
else if(nMainNum1 < nMainNum2)
return -1;
else//主版本号相同
{
if(nSubNum1 > nSubNum2)
return 1;
else if(nSubNum1 < nSubNum2)
return -1;
else//次版本号相同
{
if(nModifidNum1 > nModifidNum2)
return 1;
else if(nModifidNum1 < nModifidNum2)
return -1;
else
return 0;
}
}

}


/*将Url指向的地址的文件下载到save_as指向的本地文件*/
bool AutoUpdateThread::DownloadFile(const wstring strUrl, const wstring strSaveAs)
{
Expand Down Expand Up @@ -221,6 +249,8 @@ bool AutoUpdateThread::DownloadFile(const wstring strUrl, const wstring strSaveA
}




//发送登录信息(ip地址)
void AutoUpdateThread::SendLoginInfo()
{
Expand Down
4 changes: 4 additions & 0 deletions BesLyric/AutoUpdateThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ class AutoUpdateThread : public Singleton<AutoUpdateThread>
//自动更新执行函数
bool AutoUpdate();

//比较2个字符串版本号的大小,
int VersionCompare(const SStringW v1, const SStringW v2);

//从网络下载文件
bool DownloadFile(const wstring strUrl, const wstring strSaveAs);


//发送登录信息(ip地址)
void SendLoginInfo();

Expand Down
33 changes: 33 additions & 0 deletions Document/AutoUpdate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
�Զ�����ģ��
====================================================================================
ģ��˵����
��ģ��ʵ���Զ��������ܣ��ڳ�������������һ���߳����Զ����������Ծ�Ĭ������
ʽ�����߳��������������������ļ����������µİ汾�����������µĿ�ִ���ļ�������
�汾��Ϣ�ļ������������ķ�ʽ�������ļ���


-------------------------------------------------------------------------------------
��Ҫ�����ļ���
../BesLyric/BesAutoUpdateThread.cpp
../BesLyric/AutoUpdateThread.h

-------------------------------------------------------------------------------------
��������˵����

�������ϴ�����4���ļ�������ʹ�ò���԰���ļ��������������ļ��������ƣ���׺ʹ��zip������
�ļ����£�
http://files.cnblogs.com/files/BensonLaur/Beslyric.zip

http://files.cnblogs.com/files/BensonLaur/lastVersion.zip
http://files.cnblogs.com/files/BensonLaur/BesLyricExe.zip
http://files.cnblogs.com/files/BensonLaur/versionLog.zip

�ļ�����˵����
Beslyric.zip�����ļ�Ϊѹ�����ļ����������µ�����������������������ʵ�������ļ�

lastVersion.zip,���ļ�Ϊtxt�ļ����� lastVersion.txt���������°汾�ź����¸������ݣ�
�Զ���������ʱ������������������ļ�
BesLyricExe.zip�����ļ�Ϊexe�ļ�����BesLyric.exe�������Զ�����ʱ�������滻��ǰ�汾
versionLog.zip�����ļ�Ϊtxt�ļ����� versionLog.txt�������Զ�����ʱ�������滻�ɵİ�
����¼��

5 changes: 5 additions & 0 deletions Document/_目录说明.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Document
��Ŀ¼���ڴ���˵���ĵ������ڼ�¼��ͬģ�鿪������˵����ע������

Document/AutoUpdate.txt
�Զ�����ģ��

0 comments on commit 0b2baa5

Please sign in to comment.