diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index 967a623..7d088bb 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -59,6 +59,7 @@ true + Level3 @@ -81,13 +82,7 @@ - call "$(DevEnvDir)..\Tools\vsdevcmd.bat" -no_logo -set PostBuildTool="$(SolutionDir)PostBuildTool\bin\x86\$(Configuration)\net48\PostBuildTool" -cl PreparationScript.h /P /EP /u /nologo - if %errorlevel% neq 0 exit /b %errorlevel% -copy PreparationScript.i PreparationScript.lua /Y - if %errorlevel% neq 0 exit /b %errorlevel% -%PostBuildTool% FormatLuaScript PreparationScript.lua + PostBuildScript.bat @@ -118,13 +113,7 @@ copy PreparationScript.i PreparationScript.lua /Y - call "$(DevEnvDir)..\Tools\vsdevcmd.bat" -no_logo -set PostBuildTool="$(SolutionDir)PostBuildTool\bin\x86\$(Configuration)\net48\PostBuildTool" -cl PreparationScript.h /P /EP /u /nologo - if %errorlevel% neq 0 exit /b %errorlevel% -copy PreparationScript.i PreparationScript.lua /Y - if %errorlevel% neq 0 exit /b %errorlevel% -%PostBuildTool% FormatLuaScript PreparationScript.lua + PostBuildScript.bat @@ -167,6 +156,7 @@ copy PreparationScript.i PreparationScript.lua /Y + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 5fc1c7c..9883723 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -141,5 +141,6 @@ Header Files\LuaScript + \ No newline at end of file diff --git a/Common/PostBuildScript.bat b/Common/PostBuildScript.bat new file mode 100644 index 0000000..95ff89f --- /dev/null +++ b/Common/PostBuildScript.bat @@ -0,0 +1,9 @@ +call "%DevEnvDir%..\Tools\vsdevcmd.bat" -no_logo +set PostBuildTool="%SolutionDir%PostBuildTool\bin\x86\%Configuration%\net48\PostBuildTool" +rem Process the header file into a Lua script file +cl PreparationScript.h /P /EP /u /nologo + if %errorlevel% neq 0 exit /b %errorlevel% +rem Format and commit only if there is any content-change +copy PreparationScript.i _PreparationScript.lua /Y + if %errorlevel% neq 0 exit /b %errorlevel% +%PostBuildTool% FormatLuaScript _PreparationScript.lua PreparationScript.lua \ No newline at end of file diff --git a/PostBuild.targets b/PostBuild.targets new file mode 100644 index 0000000..e2a9d9d --- /dev/null +++ b/PostBuild.targets @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PostBuildTool/Program.cs b/PostBuildTool/Program.cs index edf059e..fcdc1d1 100644 --- a/PostBuildTool/Program.cs +++ b/PostBuildTool/Program.cs @@ -117,7 +117,8 @@ static void FormatLuaScript(string[] args) Console.WriteLine("This cmdline relies on StyLua which doesn't have a 32-bit executable file, skip Lua script formatting."); return; } - var targetPath = args.ElementAtOrDefault(0); + var inputPath = args.ElementAtOrDefault(0); + var outputPath = args.ElementAtOrDefault(1); var styluaDirPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var styluaPath = Path.Combine(styluaDirPath, "stylua.exe"); if (!File.Exists(styluaPath)) @@ -133,9 +134,20 @@ static void FormatLuaScript(string[] args) using var tmpZipStream = new ZipArchive(tmpStream); tmpZipStream.ExtractToDirectory(styluaDirPath); } - Console.WriteLine($"Format lua script: {targetPath}"); - Process.Start(new ProcessStartInfo(styluaPath, $"--column-width 999 --indent-type Spaces \"{targetPath}\"") { + Console.WriteLine($"Format lua script: {outputPath}"); + Process.Start(new ProcessStartInfo(styluaPath, $"--column-width 999 --indent-type Spaces \"{inputPath}\"") { UseShellExecute = false, }).WaitForExit(); + if (File.Exists(outputPath)) + { + var newContent = File.ReadAllText(inputPath); + var oldContent = File.ReadAllText(outputPath); + if (newContent == oldContent) + { + Console.WriteLine($"{outputPath} has no change, keep modified date."); + return; + } + } + File.Copy(inputPath, outputPath, true); } } \ No newline at end of file diff --git a/ThMouseX.sln b/ThMouseX.sln index fdf9426..1b0b51f 100644 --- a/ThMouseX.sln +++ b/ThMouseX.sln @@ -25,6 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThMouseXGUI", "ThMouseXGUI\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B337E9DD-BB1B-4851-B933-05C75CB5D9AC}" ProjectSection(SolutionItems) = preProject + PostBuild.targets = PostBuild.targets vcpkg.json = vcpkg.json EndProjectSection EndProject diff --git a/ThMouseX/PostBuildScript.bat b/ThMouseX/PostBuildScript.bat new file mode 100644 index 0000000..25d68f9 --- /dev/null +++ b/ThMouseX/PostBuildScript.bat @@ -0,0 +1,5 @@ +call "%DevEnvDir%..\Tools\vsdevcmd.bat" -no_logo +set ClientManifestPath="%SolutionDir%ThMouseXServer\client.manifest" +set ComClientPath="%OutDir%ThMouseX.dll;#2" +rem Embed the manifest file +mt -nologo -manifest %ClientManifestPath% -outputresource:%ComClientPath% \ No newline at end of file diff --git a/ThMouseX/ThMouseX.vcxproj b/ThMouseX/ThMouseX.vcxproj index a494c17..0e2745e 100644 --- a/ThMouseX/ThMouseX.vcxproj +++ b/ThMouseX/ThMouseX.vcxproj @@ -57,7 +57,8 @@ true - + + NotUsing @@ -79,10 +80,7 @@ - call "$(DevEnvDir)..\Tools\vsdevcmd.bat" -no_logo -set ClientManifestPath="$(SolutionDir)ThMouseXServer\client.manifest" -set ComClientPath="$(OutDir)ThMouseX.dll;#2" -mt -nologo -manifest %ClientManifestPath% -outputresource:%ComClientPath% + PostBuildScript.bat @@ -118,10 +116,7 @@ mt -nologo -manifest %ClientManifestPath% -outputresource:%ComClientPath% - call "$(DevEnvDir)..\Tools\vsdevcmd.bat" -no_logo -set ClientManifestPath="$(SolutionDir)ThMouseXServer\client.manifest" -set ComClientPath="$(OutDir)ThMouseX.dll;#2" -mt -nologo -manifest %ClientManifestPath% -outputresource:%ComClientPath% + PostBuildScript.bat @@ -236,6 +231,9 @@ mt -nologo -manifest %ClientManifestPath% -outputresource:%ComClientPath% + + + diff --git a/ThMouseX/ThMouseX.vcxproj.filters b/ThMouseX/ThMouseX.vcxproj.filters index 49c3da4..673e930 100644 --- a/ThMouseX/ThMouseX.vcxproj.filters +++ b/ThMouseX/ThMouseX.vcxproj.filters @@ -182,4 +182,7 @@ + + + \ No newline at end of file diff --git a/ThMouseXGUI/PostBuildScript.bat b/ThMouseXGUI/PostBuildScript.bat new file mode 100644 index 0000000..2b3f0b4 --- /dev/null +++ b/ThMouseXGUI/PostBuildScript.bat @@ -0,0 +1,11 @@ +call "%DevEnvDir%..\Tools\vsdevcmd.bat" -no_logo +rem Copy all the C++ output files into this +xcopy "%SolutionDir%%Configuration%\*" "%ProjectDir%%OutDir%" /y /s /d + if %errorlevel% neq 0 exit /b %errorlevel% +rem Copy all the files of NeoLuaBootstrap into this +xcopy "%SolutionDir%NeoLuaBootstrap\bin\x86\%Configuration%\net48\*" "%ProjectDir%%OutDir%" /y /s /d + if %errorlevel% neq 0 exit /b %errorlevel% +set ServerManifestPath="%SolutionDir%ThMouseXServer\server.manifest" +set ComServerPath="%ProjectDir%%OutDir%ThMouseXGUI.exe;#1" +rem Embed the manifest file +mt -nologo -manifest %ServerManifestPath% -outputresource:%ComServerPath% \ No newline at end of file diff --git a/ThMouseXGUI/ThMouseXGUI.csproj b/ThMouseXGUI/ThMouseXGUI.csproj index 7cf866f..a368f92 100644 --- a/ThMouseXGUI/ThMouseXGUI.csproj +++ b/ThMouseXGUI/ThMouseXGUI.csproj @@ -1,32 +1,28 @@  - - WinExe - net48 - true - enable - 12 - ThMouseX.ico - true - True - 3.0.0 - x86 - + + WinExe + net48 + true + enable + 12 + ThMouseX.ico + true + True + 3.0.0 + x86 + - - - + + + + + - - - + - - - - - - - + + + \ No newline at end of file diff --git a/ThMouseXServer/PostBuildScript.bat b/ThMouseXServer/PostBuildScript.bat new file mode 100644 index 0000000..5144cdf --- /dev/null +++ b/ThMouseXServer/PostBuildScript.bat @@ -0,0 +1,44 @@ +call "%DevEnvDir%..\Tools\vsdevcmd.bat" -no_logo +set PostBuildTool="%SolutionDir%PostBuildTool\bin\x86\%Configuration%\net48\PostBuildTool" +set ServerName=ThMouseXServer +set ClientName=ThMouseX +set TypeLibName=ThMouseXServer.dll +set Architecture=* +set ServerPath="%ProjectDir%%OutDir%ThMouseXServer.dll" +set ServerManifestPath=server.manifest +set ClientManifestPath=client.manifest +set TlbPath=server.tlb +rem Make a manifest file for the Server +%PostBuildTool% GenerateComServerManifest %ServerName% %TypeLibName% %Architecture% %ServerPath% %ServerManifestPath% + if %errorlevel% neq 0 exit /b %errorlevel% +rem Make a manifest file for the client +%PostBuildTool% GenerateComServerManifest %ClientName% %TypeLibName% %Architecture% %ServerPath% %ClientManifestPath% + if %errorlevel% neq 0 exit /b %errorlevel% +rem Generate a TypeLib file +tlbexp /nologo /win32 %ServerPath% /out:%TlbPath% + if %errorlevel% neq 0 exit /b %errorlevel% +rem Embed the Typelib file into the Server dll file +%PostBuildTool% ImportResource %ServerPath% %TlbPath% typelib #1 + if %errorlevel% neq 0 exit /b %errorlevel% +if not exist AutoGenerated mkdir AutoGenerated +cd AutoGenerated +rem Update the tlh and tli only if their content changes +ren server.tlh old_server.tlh > nul 2> nul +ren server.tli old_server.tli > nul 2> nul +cl -nologo "%ProjectDir%GenerateComHeaders.cpp" +fc server.tlh old_server.tlh > nul 2> nul +if %errorlevel% neq 0 ( + rem There are changes + del old_server.tlh > nul 2> nul + del old_server.tli > nul 2> nul +) else ( + rem No change + del server.tlh + del server.tli + ren old_server.tlh server.tlh > nul + ren old_server.tli server.tli > nul +) +rem Remove trash +del GenerateComHeaders.exe +del GenerateComHeaders.obj +cd .. \ No newline at end of file diff --git a/ThMouseXServer/ThMouseXServer.csproj b/ThMouseXServer/ThMouseXServer.csproj index 38108bc..6a37054 100644 --- a/ThMouseXServer/ThMouseXServer.csproj +++ b/ThMouseXServer/ThMouseXServer.csproj @@ -1,33 +1,32 @@ - + - - net48 - enable - enable - 12 - true - x86 - - - - - - - - - - + + net48 + enable + enable + 12 + true + x86 + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + +