diff --git a/Plugins/API/DllExporter/AssemblyInfo.cs b/Build/DllExporter/AssemblyInfo.cs similarity index 97% rename from Plugins/API/DllExporter/AssemblyInfo.cs rename to Build/DllExporter/AssemblyInfo.cs index c8267cd4..c23d01a9 100644 --- a/Plugins/API/DllExporter/AssemblyInfo.cs +++ b/Build/DllExporter/AssemblyInfo.cs @@ -1,7 +1,7 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyCopyright("© 2013 - Birunthan Mohanathas")] -[assembly: AssemblyVersion("1.0.1.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyCopyright("© 2013 - Birunthan Mohanathas")] +[assembly: AssemblyVersion("1.0.1.0")] [assembly: AssemblyProduct("Rainmeter")] \ No newline at end of file diff --git a/Plugins/API/DllExporter/DllExporter.csproj b/Build/DllExporter/DllExporter.csproj similarity index 81% rename from Plugins/API/DllExporter/DllExporter.csproj rename to Build/DllExporter/DllExporter.csproj index 4cf20b5c..7079b9f3 100644 --- a/Plugins/API/DllExporter/DllExporter.csproj +++ b/Build/DllExporter/DllExporter.csproj @@ -1,94 +1,82 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {49D56CA5-54AB-45C9-A245-EAE588FCBFE1} - Exe - Properties - DllExporter - DllExporter - v4.0 - 512 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - x86 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - 1607 - - - x86 - none - true - bin\Release\ - TRACE - prompt - 4 - 1607 - - - OnOutputUpdated - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - 1607 - - - bin\x64\Release\ - TRACE - true - none - x64 - prompt - 1607 - - - - - - - - - - - - - - if not exist "$(SolutionDir)Plugins\API\DllExporter.exe" (move "$(TargetPath)" "$(SolutionDir)Plugins\API\DllExporter.exe") - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {49D56CA5-54AB-45C9-A245-EAE588FCBFE1} + Exe + Properties + DllExporter + DllExporter + v4.0 + 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + $(SolutionDir)x32-$(Configuration)\Tools\ + $(SolutionDir)x64-$(Configuration)\Tools\ + + + x86 + true + full + false + DEBUG;TRACE + prompt + 4 + 1607 + + + x86 + none + true + TRACE + prompt + 4 + 1607 + + + OnOutputUpdated + + + true + DEBUG;TRACE + full + x64 + prompt + 1607 + + + TRACE + true + none + x64 + prompt + 1607 + + + + + + + + + + + + \ No newline at end of file diff --git a/Plugins/API/DllExporter/Program.cs b/Build/DllExporter/Program.cs similarity index 97% rename from Plugins/API/DllExporter/Program.cs rename to Build/DllExporter/Program.cs index 5b6954d1..d9ad841c 100644 --- a/Plugins/API/DllExporter/Program.cs +++ b/Build/DllExporter/Program.cs @@ -1,233 +1,241 @@ -/* - Copyright (C) 2011 Birunthan Mohanathas - - 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 - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -using System; -using System.Collections.Generic; -using System.Text; -using System.Diagnostics; -using Microsoft.Build.Utilities; -using System.IO; - -namespace DllExporter -{ - class Program - { - static int Main(string[] args) - { - string configurationName = args[0]; - string platformTarget = args[1]; - string targetDirectory = args[2]; - string targetDllName = targetDirectory + args[3]; - string targetIlName = targetDllName + ".il"; - string targetResName = targetDllName + ".res"; - - bool is64 = platformTarget.ToLower().Equals("x64"); - bool isDebug = configurationName.ToLower().Equals("debug"); - - string ilasmPath = FindIlasmPath(is64); - if (ilasmPath == null) - { - Console.WriteLine("DllExporter error: ilasm.exe not found"); - return 1; - } - - string ildasmPath = FindIldasmPath(); - if (ildasmPath == null) - { - Console.WriteLine("DllExporter error: ildasm.exe not found"); - return 1; - } - - Directory.SetCurrentDirectory(targetDirectory); - - // Disassemble - Process ildasmProc = new Process(); - string ildasmArgs = string.Format( - "/nobar {0} /output=\"{1}\" \"{2}\"", - isDebug ? "/linenum" : "", - targetIlName, - targetDllName); - - ildasmProc.StartInfo = new ProcessStartInfo(ildasmPath, ildasmArgs); - ildasmProc.StartInfo.UseShellExecute = false; - ildasmProc.StartInfo.CreateNoWindow = false; - ildasmProc.StartInfo.RedirectStandardOutput = true; - ildasmProc.Start(); - ildasmProc.WaitForExit(); - - if (ildasmProc.ExitCode != 0) - { - Console.WriteLine("DllExporter error: Unable to disassemble!"); - Console.WriteLine(ildasmProc.StandardOutput.ReadToEnd()); - return ildasmProc.ExitCode; - } - - bool hasResource = File.Exists(targetResName); - - // Read disassembly and find methods marked with DllExport attribute - List lines = new List(File.ReadAllLines(targetIlName)); - int attributeIndex = 0; - int exportCount = 0; - while (true) - { - attributeIndex = lines.FindIndex(attributeIndex, new Predicate(x => x.Contains(".custom instance void") && x.Contains("DllExport::.ctor()"))); - if (attributeIndex < 8) break; - - int methodIndex = lines.FindLastIndex(attributeIndex, attributeIndex, new Predicate(x => x.Contains(".method"))); - if (methodIndex == -1) - { - Console.WriteLine("DllExporter error: Unable to parse disassembly (.method not found)!"); - return 1; - } - - int functionIndex = lines.FindIndex(methodIndex, new Predicate(x => x.Contains("("))); - if (functionIndex == -1) - { - Console.WriteLine("DllExporter error: Unable to parse disassembly (bracket not found)!"); - return 1; - } - - int bracketPos = lines[functionIndex].IndexOf('('); - int functionNamePos = lines[functionIndex].LastIndexOf(' ', bracketPos); - string functionName = lines[functionIndex].Substring(functionNamePos, bracketPos - functionNamePos); - - // Change calling convention to cdecl - lines[functionIndex] = string.Format("{0} modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) {1}", lines[functionIndex].Substring(0, functionNamePos - 1), lines[functionIndex].Substring(functionNamePos)); - - int attributeBeginPos = lines[attributeIndex].IndexOf('.'); - string spaces = new string(' ', attributeBeginPos); - - // Replace attribute with export - ++exportCount; - lines[attributeIndex] = string.Format("{0}.export [{1}] as {2}", spaces, exportCount, functionName); - - ++attributeIndex; - } - - if (exportCount == 0) - { - Console.WriteLine("DllExporter warning: Nothing found to export."); - } - - // Remove the DllExport class - int classIndex = lines.FindIndex(new Predicate(x => x.Contains(".class ") && x.EndsWith(".DllExport"))); - if (classIndex == -1) - { - Console.WriteLine("DllExporter error: Unable to parse disassembly (DllExport class not found)!"); - return 1; - } - else - { - int classEndIndex = lines.FindIndex(classIndex, new Predicate(x => x.Contains("} // end of class") && x.EndsWith(".DllExport"))); - if (classEndIndex == -1) - { - Console.WriteLine("DllExporter error: Unable to parse disassembly (DllExport class end not found)!"); - return 1; - } - - lines.RemoveRange(classIndex, classEndIndex - classIndex + 2); - } - - // Write everything back - File.WriteAllLines(targetIlName, lines.ToArray()); - - // Reassemble - Process ilasmProc = new Process(); - string resource = hasResource ? string.Format("/resource=\"{0}\"", targetResName) : ""; - string ilasmArgs = string.Format("/nologo /quiet /dll {0} {1} /output=\"{2}\" {3} \"{4}\"", isDebug ? "/debug /pdb" : "/optimize", is64 ? "/x64 /PE64" : "", targetDllName, resource, targetIlName); - ilasmProc.StartInfo = new ProcessStartInfo(ilasmPath, ilasmArgs); - ilasmProc.StartInfo.UseShellExecute = false; - ilasmProc.StartInfo.CreateNoWindow = false; - ilasmProc.StartInfo.RedirectStandardOutput = true; - ilasmProc.Start(); - ilasmProc.WaitForExit(); - - if (ilasmProc.ExitCode != 0) - { - Console.WriteLine("DllExporter error: Unable to assemble!"); - Console.WriteLine(ilasmProc.StandardOutput.ReadToEnd()); - return ilasmProc.ExitCode; - } - - // Cleanup - File.Delete(targetIlName); - File.Delete(targetResName); - - return 0; - } - - /// - /// Finds path to ilasm.exe. - /// - private static string FindIlasmPath(bool x64) - { - var arch = x64 ? DotNetFrameworkArchitecture.Bitness64 : DotNetFrameworkArchitecture.Bitness32; - var path = ToolLocationHelper.GetPathToDotNetFrameworkFile( - "ilasm.exe", TargetDotNetFrameworkVersion.Version20, arch); - return File.Exists(path) ? path : null; - } - - /// - /// Finds path to ildasm.exe. - /// - private static string FindIldasmPath() - { - var sdkPath = Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Microsoft SDKs\Windows\"); - if (!Directory.Exists(sdkPath)) - { - sdkPath = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft SDKs\Windows\"); - } - - if (!Directory.Exists(sdkPath)) - { - throw new DirectoryNotFoundException("'Microsoft SDKs' directory not found"); - } - - // Get the version directories. - var sdkVersionDirectories = Directory.GetDirectories(sdkPath); - foreach (var sdkVersionDirectory in sdkVersionDirectories) - { - var binDirectory = Path.Combine(sdkVersionDirectory, @"bin"); - if (!Directory.Exists(binDirectory)) - { - continue; - } - - // Check for e.g. 'Microsoft SDKs\v8.0A\bin\ildasm.exe'. - var ildasmPath = Path.Combine(binDirectory, @"ildasm.exe"); - if (File.Exists(ildasmPath)) - { - return ildasmPath; - } - - // Check for e.g. 'Microsoft SDKs\v8.0A\bin\NETFX 4.0 Tools\ildasm.exe'. - var toolsDirectories = Directory.GetDirectories(binDirectory, "NETFX*Tools"); - foreach (var toolDirectory in toolsDirectories) - { - ildasmPath = Path.Combine(toolDirectory, @"ildasm.exe"); - if (File.Exists(ildasmPath)) - { - return ildasmPath; - } - } - } - - return null; - } - } -} +/* + Copyright (C) 2011 Birunthan Mohanathas + + 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 + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; +using Microsoft.Build.Utilities; +using System.IO; + +namespace DllExporter +{ + class Program + { + static int Main(string[] args) + { + if (args.Length < 4) + { + Console.WriteLine("DllExporter error: Invalid arguments"); + return 1; + } + + string configurationName = args[0]; + string platformTarget = args[1]; + string targetDirectory = args[2]; + string targetDllName = targetDirectory + args[3]; + string targetIlName = targetDllName + ".il"; + string targetResName = targetDllName + ".res"; + + bool is64 = platformTarget.ToLower().Equals("x64"); + bool isDebug = configurationName.ToLower().Equals("debug"); + + string ilasmPath = FindIlasmPath(is64); + if (ilasmPath == null) + { + Console.WriteLine("DllExporter error: ilasm.exe not found"); + return 1; + } + + string ildasmPath = FindIldasmPath(); + if (ildasmPath == null) + { + Console.WriteLine("DllExporter error: ildasm.exe not found"); + return 1; + } + + Directory.SetCurrentDirectory(targetDirectory); + + // Disassemble + Process ildasmProc = new Process(); + string ildasmArgs = string.Format( + "/nobar {0} /output=\"{1}\" \"{2}\"", + isDebug ? "/linenum" : "", + targetIlName, + targetDllName); + + ildasmProc.StartInfo = new ProcessStartInfo(ildasmPath, ildasmArgs); + ildasmProc.StartInfo.UseShellExecute = false; + ildasmProc.StartInfo.CreateNoWindow = false; + ildasmProc.StartInfo.RedirectStandardOutput = true; + ildasmProc.Start(); + ildasmProc.WaitForExit(); + + if (ildasmProc.ExitCode != 0) + { + Console.WriteLine("DllExporter error: Unable to disassemble!"); + Console.WriteLine(ildasmProc.StandardOutput.ReadToEnd()); + return ildasmProc.ExitCode; + } + + bool hasResource = File.Exists(targetResName); + + // Read disassembly and find methods marked with DllExport attribute + List lines = new List(File.ReadAllLines(targetIlName)); + int attributeIndex = 0; + int exportCount = 0; + while (true) + { + attributeIndex = lines.FindIndex(attributeIndex, new Predicate(x => x.Contains(".custom instance void") && x.Contains("DllExport::.ctor()"))); + if (attributeIndex < 8) break; + + int methodIndex = lines.FindLastIndex(attributeIndex, attributeIndex, new Predicate(x => x.Contains(".method"))); + if (methodIndex == -1) + { + Console.WriteLine("DllExporter error: Unable to parse disassembly (.method not found)!"); + return 1; + } + + int functionIndex = lines.FindIndex(methodIndex, new Predicate(x => x.Contains("("))); + if (functionIndex == -1) + { + Console.WriteLine("DllExporter error: Unable to parse disassembly (bracket not found)!"); + return 1; + } + + int bracketPos = lines[functionIndex].IndexOf('('); + int functionNamePos = lines[functionIndex].LastIndexOf(' ', bracketPos); + string functionName = lines[functionIndex].Substring(functionNamePos, bracketPos - functionNamePos); + + // Change calling convention to cdecl + lines[functionIndex] = string.Format("{0} modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) {1}", lines[functionIndex].Substring(0, functionNamePos - 1), lines[functionIndex].Substring(functionNamePos)); + + int attributeBeginPos = lines[attributeIndex].IndexOf('.'); + string spaces = new string(' ', attributeBeginPos); + + // Replace attribute with export + ++exportCount; + lines[attributeIndex] = string.Format("{0}.export [{1}] as {2}", spaces, exportCount, functionName); + + ++attributeIndex; + } + + if (exportCount == 0) + { + Console.WriteLine("DllExporter warning: Nothing found to export."); + } + + // Remove the DllExport class + int classIndex = lines.FindIndex(new Predicate(x => x.Contains(".class ") && x.EndsWith(".DllExport"))); + if (classIndex == -1) + { + Console.WriteLine("DllExporter error: Unable to parse disassembly (DllExport class not found)!"); + return 1; + } + else + { + int classEndIndex = lines.FindIndex(classIndex, new Predicate(x => x.Contains("} // end of class") && x.EndsWith(".DllExport"))); + if (classEndIndex == -1) + { + Console.WriteLine("DllExporter error: Unable to parse disassembly (DllExport class end not found)!"); + return 1; + } + + lines.RemoveRange(classIndex, classEndIndex - classIndex + 2); + } + + // Write everything back + File.WriteAllLines(targetIlName, lines.ToArray()); + + // Reassemble + Process ilasmProc = new Process(); + string resource = hasResource ? string.Format("/resource=\"{0}\"", targetResName) : ""; + string ilasmArgs = string.Format("/nologo /quiet /dll {0} {1} /output=\"{2}\" {3} \"{4}\"", isDebug ? "/debug /pdb" : "/optimize", is64 ? "/x64 /PE64" : "", targetDllName, resource, targetIlName); + ilasmProc.StartInfo = new ProcessStartInfo(ilasmPath, ilasmArgs); + ilasmProc.StartInfo.UseShellExecute = false; + ilasmProc.StartInfo.CreateNoWindow = false; + ilasmProc.StartInfo.RedirectStandardOutput = true; + ilasmProc.Start(); + ilasmProc.WaitForExit(); + + if (ilasmProc.ExitCode != 0) + { + Console.WriteLine("DllExporter error: Unable to assemble!"); + Console.WriteLine(ilasmProc.StandardOutput.ReadToEnd()); + return ilasmProc.ExitCode; + } + + // Cleanup + File.Delete(targetIlName); + File.Delete(targetResName); + + Console.WriteLine("DllExporter: Processed {0}", args[3]); + + return 0; + } + + /// + /// Finds path to ilasm.exe. + /// + private static string FindIlasmPath(bool x64) + { + var arch = x64 ? DotNetFrameworkArchitecture.Bitness64 : DotNetFrameworkArchitecture.Bitness32; + var path = ToolLocationHelper.GetPathToDotNetFrameworkFile( + "ilasm.exe", TargetDotNetFrameworkVersion.Version20, arch); + return File.Exists(path) ? path : null; + } + + /// + /// Finds path to ildasm.exe. + /// + private static string FindIldasmPath() + { + var sdkPath = Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Microsoft SDKs\Windows\"); + if (!Directory.Exists(sdkPath)) + { + sdkPath = Environment.ExpandEnvironmentVariables(@"%ProgramFiles(x86)%\Microsoft SDKs\Windows\"); + } + + if (!Directory.Exists(sdkPath)) + { + throw new DirectoryNotFoundException("'Microsoft SDKs' directory not found"); + } + + // Get the version directories. + var sdkVersionDirectories = Directory.GetDirectories(sdkPath); + foreach (var sdkVersionDirectory in sdkVersionDirectories) + { + var binDirectory = Path.Combine(sdkVersionDirectory, @"bin"); + if (!Directory.Exists(binDirectory)) + { + continue; + } + + // Check for e.g. 'Microsoft SDKs\v8.0A\bin\ildasm.exe'. + var ildasmPath = Path.Combine(binDirectory, @"ildasm.exe"); + if (File.Exists(ildasmPath)) + { + return ildasmPath; + } + + // Check for e.g. 'Microsoft SDKs\v8.0A\bin\NETFX 4.0 Tools\ildasm.exe'. + var toolsDirectories = Directory.GetDirectories(binDirectory, "NETFX*Tools"); + foreach (var toolDirectory in toolsDirectories) + { + ildasmPath = Path.Combine(toolDirectory, @"ildasm.exe"); + if (File.Exists(ildasmPath)) + { + return ildasmPath; + } + } + } + + return null; + } + } +} diff --git a/Plugins/PluginInputText/PluginInputText.csproj b/Plugins/PluginInputText/PluginInputText.csproj index 92e29f1b..b013828f 100644 --- a/Plugins/PluginInputText/PluginInputText.csproj +++ b/Plugins/PluginInputText/PluginInputText.csproj @@ -97,9 +97,9 @@ InputBox.cs - + - "$(SolutionDir)Plugins\API\DllExporter.exe" "$(ConfigurationName)" "$(PlatformName)" "$(TargetDir)\" "$(TargetFileName)" + "$(RmOutDirRoot)Tools\DllExporter.exe" "$(ConfigurationName)" "$(PlatformName)" "$(TargetDir)\" "$(TargetFileName)" \ No newline at end of file diff --git a/Rainmeter.sln b/Rainmeter.sln index a8b9e74b..873f5895 100644 --- a/Rainmeter.sln +++ b/Rainmeter.sln @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcx EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common_Test", "Common\Common_Test.vcxproj", "{442084A6-2069-4927-B0C9-51525A720CB2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DllExporter", "Build\DllExporter\DllExporter.csproj", "{49D56CA5-54AB-45C9-A245-EAE588FCBFE1}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Installer", "Installer\Installer.vcxproj", "{2FCFBFD2-2720-4BDD-B620-4BDD3DBB8D3D}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Language", "Language\Language.vcxproj", "{6BE6F228-B741-4DA9-9FBC-E9F2A7BD483A}" @@ -32,8 +34,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SkinInstallerLauncher", "Sk {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA} = {6F5D4C4A-C8C3-41DA-BF44-6D42B76464DA} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DllExporter", "Plugins\API\DllExporter\DllExporter.csproj", "{49D56CA5-54AB-45C9-A245-EAE588FCBFE1}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginAdvancedCPU", "Plugins\PluginAdvancedCPU\PluginAdvancedCPU.vcxproj", "{EE8EC522-8430-4B46-86A3-D943D77F9E4B}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginCoreTemp", "Plugins\PluginCoreTemp\PluginCoreTemp.vcxproj", "{F32FA418-8DF4-4E94-B92B-EBD502F5DC07}" @@ -43,6 +43,9 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginFolderInfo", "Plugins\PluginFolderInfo\PluginFolderInfo.vcxproj", "{A221819D-4263-42AA-B22A-C022924842A7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginInputText", "Plugins\PluginInputText\PluginInputText.csproj", "{2CFEC79A-E39E-4FFD-ABC2-C4A69DD1E44D}" + ProjectSection(ProjectDependencies) = postProject + {49D56CA5-54AB-45C9-A245-EAE588FCBFE1} = {49D56CA5-54AB-45C9-A245-EAE588FCBFE1} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginiTunes", "Plugins\PluginiTunes\PluginiTunes.vcxproj", "{A2DD3CBE-B140-4892-A875-24107FA52518}" EndProject