forked from SomeSupport/eMule
-
Notifications
You must be signed in to change notification settings - Fork 97
/
ClientVersionInfo.h
177 lines (158 loc) · 6.43 KB
/
ClientVersionInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
#pragma once
#include "emule.h"
#include "updownclient.h"
// class to convert peercache Client versions to comparable values.
#define CVI_IGNORED -1
// == means same client type, same or ignored version (for example eMule/0.4.* == eMule/0.4.2 )
// != means different client or different defined version (for example eMule/0.4.2 != SomeClient/0.4.2 )
// > mean _same client type_ and higher version, which therefor cannot be completely undefined ( for example eMule/1.* > eMule/0.4.2 )
// >= same as > but here the version can be undefined ( for example eMule/* >= eMule/0.4.2 )
class CClientVersionInfo{
public:
CClientVersionInfo(CString strPCEncodedVersion)
{
m_nVerMajor = (UINT)CVI_IGNORED;
m_nVerMinor = (UINT)CVI_IGNORED;
m_nVerUpdate = (UINT)CVI_IGNORED;
m_nVerBuild = (UINT)CVI_IGNORED;
m_ClientTypeMajor = SO_UNKNOWN;
m_ClientTypeMinor = SO_UNKNOWN;
int posSeperator = strPCEncodedVersion.Find('/',1);
if (posSeperator == (-1) || strPCEncodedVersion.GetLength() - posSeperator < 2){
theApp.QueueDebugLogLine( false, _T("PeerCache Error: Bad Version info in PeerCache Descriptor found: %s"), strPCEncodedVersion);
return;
}
CString strClientType = strPCEncodedVersion.Left(posSeperator).Trim();
CString strVersionNumber = strPCEncodedVersion.Mid(posSeperator+1).Trim();
if (strClientType.CompareNoCase(_T("eMule")) == 0)
m_ClientTypeMajor = SO_EMULE;
else if (strClientType.CompareNoCase(_T("eDonkey")) == 0)
m_ClientTypeMajor = SO_EDONKEYHYBRID;
// can add more types here
else{
theApp.QueueDebugLogLine(false, _T("PeerCache Warning: Unknown Clienttype in descriptor file found"));
m_ClientTypeMajor = SO_UNKNOWN;
}
int curPos2= 0;
CString strNumber = strVersionNumber.Tokenize(_T("."),curPos2);
if (strNumber.IsEmpty())
return;
else if (strNumber == _T("*"))
m_nVerMajor = (UINT)-1;
else
m_nVerMajor = _tstoi(strNumber);
strNumber = strVersionNumber.Tokenize(_T("."),curPos2);
if (strNumber.IsEmpty())
return;
else if (strNumber == _T("*"))
m_nVerMinor = (UINT)-1;
else
m_nVerMinor = _tstoi(strNumber);
strNumber = strVersionNumber.Tokenize(_T("."),curPos2);
if (strNumber.IsEmpty())
return;
else if (strNumber == _T("*"))
m_nVerUpdate = (UINT)-1;
else
m_nVerUpdate = _tstoi(strNumber);
strNumber = strVersionNumber.Tokenize(_T("."),curPos2);
if (strNumber.IsEmpty())
return;
else if (strNumber == _T("*"))
m_nVerBuild = (UINT)-1;
else
m_nVerBuild = _tstoi(strNumber);
}
CClientVersionInfo(uint32 dwTagVersionInfo, UINT nClientMajor)
{
UINT nClientMajVersion = (dwTagVersionInfo >> 17) & 0x7f;
UINT nClientMinVersion = (dwTagVersionInfo>> 10) & 0x7f;
UINT nClientUpVersion = (dwTagVersionInfo >> 7) & 0x07;
CClientVersionInfo(nClientMajVersion, nClientMinVersion, nClientUpVersion, (UINT)CVI_IGNORED, nClientMajor, SO_UNKNOWN);
}
CClientVersionInfo(uint32 nVerMajor, uint32 nVerMinor, uint32 nVerUpdate, uint32 nVerBuild, uint32 ClientTypeMajor, uint32 ClientTypeMinor = SO_UNKNOWN)
{
m_nVerMajor = nVerMajor;
m_nVerMinor = nVerMinor;
m_nVerUpdate = nVerUpdate;
m_nVerBuild = nVerBuild;
m_ClientTypeMajor = ClientTypeMajor;
m_ClientTypeMinor = ClientTypeMinor;
}
CClientVersionInfo(){
CClientVersionInfo((UINT)CVI_IGNORED, (UINT)CVI_IGNORED, (UINT)CVI_IGNORED, (UINT)CVI_IGNORED, SO_UNKNOWN, SO_UNKNOWN);
}
CClientVersionInfo(const CClientVersionInfo& cv) {*this = cv;}
CClientVersionInfo& operator=(const CClientVersionInfo& cv)
{
m_nVerMajor = cv.m_nVerMajor;
m_nVerMinor = cv.m_nVerMinor;
m_nVerUpdate = cv.m_nVerUpdate;
m_nVerBuild = cv.m_nVerBuild;
m_ClientTypeMajor = cv.m_ClientTypeMajor;
m_ClientTypeMinor = cv.m_ClientTypeMinor;
return *this;
}
friend bool operator==(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
return ( (c1.m_nVerMajor == (-1) || c2.m_nVerMajor == (-1) || c1.m_nVerMajor == c2.m_nVerMajor)
&& (c1.m_nVerMinor == (-1) || c2.m_nVerMinor == (-1) || c1.m_nVerMinor == c2.m_nVerMinor)
&& (c1.m_nVerUpdate == (-1) || c2.m_nVerUpdate == (-1) || c1.m_nVerUpdate == c2.m_nVerUpdate)
&& (c1.m_nVerBuild == (-1) || c2.m_nVerBuild == (-1) || c1.m_nVerBuild == c2.m_nVerBuild)
&& (c1.m_ClientTypeMajor == (-1) || c2.m_ClientTypeMajor == (-1) || c1.m_ClientTypeMajor == c2.m_ClientTypeMajor)
&& (c1.m_ClientTypeMinor == (-1) || c2.m_ClientTypeMinor == (-1) || c1.m_ClientTypeMinor == c2.m_ClientTypeMinor)
);
}
friend bool operator !=(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
return !(c1 == c2);
}
friend bool operator >(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
if ( (c1.m_ClientTypeMajor == (-1) || c2.m_ClientTypeMajor == (-1) || c1.m_ClientTypeMajor != c2.m_ClientTypeMajor)
|| (c1.m_ClientTypeMinor != c2.m_ClientTypeMinor))
return false;
if (c1.m_nVerMajor != (-1) && c2.m_nVerMajor != (-1) && c1.m_nVerMajor > c2.m_nVerMajor)
return true;
if (c1.m_nVerMinor != (-1) && c2.m_nVerMinor != (-1) && c1.m_nVerMinor > c2.m_nVerMinor)
return true;
if (c1.m_nVerUpdate != (-1) && c2.m_nVerUpdate != (-1) && c1.m_nVerUpdate > c2.m_nVerUpdate)
return true;
if (c1.m_nVerBuild != (-1) && c2.m_nVerBuild != (-1) && c1.m_nVerBuild > c2.m_nVerBuild)
return true;
return false;
}
friend bool operator <(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
return c2 > c1;
}
friend bool operator <=(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
return c2 > c1 || c1 == c2;
}
friend bool operator >=(const CClientVersionInfo& c1, const CClientVersionInfo& c2)
{
return c1 > c2 || c1 == c2;
}
UINT m_nVerMajor;
UINT m_nVerMinor;
UINT m_nVerUpdate;
UINT m_nVerBuild;
UINT m_ClientTypeMajor;
UINT m_ClientTypeMinor; //unused atm
};