Parcourir la source

1、新增Python27目录是32位系统还是64位系统目录,以正确读取出Python27注册表的路径;
2、新增编译选项:RTEST,用于在Release版本时,以控制台程序运行(主要用于虚拟机测试时);

scbc.sat2 il y a 5 ans
Parent
commit
29af7886e9

+ 16 - 2
SATService/SATService/Global.cpp

@@ -1100,6 +1100,7 @@ namespace GLOBAL
 	void WriteTextLog(const TCHAR* format, ...)
 	{
 		AutoThreadSection aSection(&g_csTextLog);
+#ifndef RTEST
 		// 解析出日志路径;
 		TCHAR szlogpath[MAX_PATH] = { 0 };
 		_stprintf_s(szlogpath, _T("%s%s.txt"), g_szCurModuleDir, g_szFna);
@@ -1122,7 +1123,7 @@ namespace GLOBAL
 		// 格式化前设置语言区域;
 		TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
 		_tsetlocale(LC_CTYPE, _T("chs"));//设定中文;
-
+#endif
 		// 格式化日志内容;
 		va_list		args = NULL;
 		int			len = 0;
@@ -1137,6 +1138,8 @@ namespace GLOBAL
 		__time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
 		struct tm gmtm = { 0 };
 		localtime_s(&gmtm, &gmt); // 时间戳转成本地时间;
+
+#ifndef RTEST
 		_ftprintf(fp, _T("%04d-%02d-%02d %02d:%02d:%02d %s\n"), gmtm.tm_year + 1990, gmtm.tm_mon + 1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, buffer);
 
 		// 关闭文件,释放资源并设置回原语言区域;
@@ -1144,6 +1147,10 @@ namespace GLOBAL
 		fclose(fp);
 		_tsetlocale(LC_CTYPE, old_locale);
 		free(old_locale);//还原区域设定;
+#else
+		printf(_T("%04d-%02d-%02d %02d:%02d:%02d %s\n"), gmtm.tm_year + 1990, gmtm.tm_mon + 1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec, buffer);
+		free(buffer);
+#endif
 	}
 
 	void WritePythonLog(LPCTSTR file, const TCHAR* msg)
@@ -1395,8 +1402,15 @@ namespace GLOBAL
 
 	BOOL Python27Dir()
 	{
+		BOOL bIsWow64 = FALSE;
+		std::string strPython27Reg = "SOFTWARE\\Python\\PythonCore\\2.7\\InstallPath";
+		IsWow64Process(GetCurrentProcess(), &bIsWow64);
+		if ( bIsWow64 ){
+			strPython27Reg = "SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath";
+		}
+
 		HKEY hKey;
-		int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath"), 0, KEY_QUERY_VALUE, &hKey);
+		int ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPython27Reg.c_str(), 0, KEY_QUERY_VALUE, &hKey);
 		if (ret != ERROR_SUCCESS)
 			return FALSE;
 

+ 1 - 1
SATService/SATService/SATService.cpp

@@ -68,7 +68,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 		GLOBAL::GetMacAddress();
 		GLOBAL::GetLocalAddress();
 		GLOBAL::WriteTextLog("SATService goto start, tcp port = %ld", GLOBAL::g_stSATConfig.dwTCPSvrPort);
-#ifdef _DEBUG
+#ifdef RTEST
 		printf("·þÎñ¶ËTCP¶Ë¿ÚºÅ=%ld\n", GLOBAL::g_stSATConfig.dwTCPSvrPort);
 		WorkStart();
 

+ 105 - 1
SATService/SATService/SATService.vcproj

@@ -170,7 +170,87 @@
 			/>
 			<Tool
 				Name="VCPostBuildEventTool"
-				CommandLine="copy $(ProjectDir)SATProtocol.h ..\..\SATHelper\SATHelper\SATProtocol.h /y/a&#x0D;&#x0A;copy $(OutDir)\$(ProjectName).exe D:\SAT\SATService\$(ProjectName).exe /y/a"
+				CommandLine="copy $(ProjectDir)SATProtocol.h ..\..\SATHelper\SATHelper\SATProtocol.h /y/a&#x0D;&#x0A;copy $(OutDir)\$(ProjectName).exe D:\SAT\SATService\$(ProjectName).exe /y/a&#x0D;&#x0A;"
+			/>
+		</Configuration>
+		<Configuration
+			Name="RTest|Win32"
+			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
+			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="1"
+			UseOfMFC="2"
+			CharacterSet="2"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="2"
+				EnableIntrinsicFunctions="true"
+				AdditionalIncludeDirectories="../cJSON;C:\Python27\Include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;RTEST"
+				RuntimeLibrary="2"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				WarningLevel="3"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="C:\Python27\libs"
+				UACExecutionLevel="2"
+				GenerateDebugInformation="true"
+				SubSystem="1"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine="copy $(ProjectDir)SATProtocol.h ..\..\SATHelper\SATHelper\SATProtocol.h /y/a&#x0D;&#x0A;copy $(OutDir)\$(ProjectName).exe D:\SAT\SATService\$(ProjectName).exe /y/a&#x0D;&#x0A;"
 			/>
 		</Configuration>
 	</Configurations>
@@ -217,6 +297,14 @@
 						UsePrecompiledHeader="1"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="RTest|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath=".\WindowService.cpp"
@@ -317,6 +405,14 @@
 						UsePrecompiledHeader="0"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="RTest|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="0"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\cJson\cJSON.h"
@@ -401,6 +497,14 @@
 						UsePrecompiledHeader="0"
 					/>
 				</FileConfiguration>
+				<FileConfiguration
+					Name="RTest|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="0"
+					/>
+				</FileConfiguration>
 			</File>
 			<File
 				RelativePath=".\tinyxml2.h"