Reintegrated 2.3 branch into trunk

This commit is contained in:
Birunthan Mohanathas
2012-01-08 17:35:29 +00:00
parent c3335adec5
commit c3ed2e5fa3
87 changed files with 5379 additions and 2732 deletions

View File

@ -0,0 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyCopyright("© 2011 - Birunthan Mohanathas")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyProduct("Rainmeter")]

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{49D56CA5-54AB-45C9-A245-EAE588FCBFE1}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DllExporter</RootNamespace>
<AssemblyName>DllExporter</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1607</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>TestBench\x32\Debug\Rainmeter.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1607</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>TestBench\x32\Release\Rainmeter.exe</StartProgram>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<NoWarn>1607</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>TestBench\x64\Debug\Rainmeter.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<NoWarn>1607</NoWarn>
<StartAction>Program</StartAction>
<StartProgram>TestBench\x64\Release\Rainmeter.exe</StartProgram>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>move "$(TargetPath)" "$(SolutionDir)Plugins\API\DllExporter.exe"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,155 @@
/*
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
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";
string ilasmPath = args[4];
string ildasmPath = args[5];
System.IO.Directory.SetCurrentDirectory(targetDirectory);
bool is64 = platformTarget.ToLower().Equals("x64");
bool isDebug = configurationName.ToLower().Equals("debug");
// Disassemble
Process ildasmProc = new Process();
string ildasmArgs = string.Format("/nobar /output={0} {1}", 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 = System.IO.File.Exists(targetResName);
// Read disassembly and find methods marked with DllExport attribute
List<string> lines = new List<string>(System.IO.File.ReadAllLines(targetIlName));
int attributeIndex = 0;
int exportCount = 0;
while (true)
{
attributeIndex = lines.FindIndex(attributeIndex, new Predicate<string>(x => x.Contains(".custom instance void") && x.Contains("DllExport::.ctor()")));
if (attributeIndex < 8) break;
int methodIndex = lines.FindLastIndex(attributeIndex, attributeIndex, new Predicate<string>(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<string>(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<string>(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<string>(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
System.IO.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
System.IO.File.Delete(targetIlName);
System.IO.File.Delete(targetResName);
return 0;
}
}
}

130
Plugins/API/Rainmeter.cs Normal file
View File

@ -0,0 +1,130 @@
/*
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Runtime.InteropServices;
namespace Rainmeter
{
/// <summary>
/// Wrapper around the Rainmeter C API.
/// </summary>
public class API
{
private IntPtr m_Rm;
public API(IntPtr rm)
{
m_Rm = rm;
}
public static unsafe char* ToUnsafe(string s)
{
fixed (char* p = s) return p;
}
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto)]
private extern static unsafe char* RmReadString(void* rm, char* option, char* defValue, int replaceMeasures);
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto)]
private extern static unsafe double RmReadFormula(void* rm, char* option, double defValue);
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto)]
private extern static unsafe char* RmPathToAbsolute(void* rm, char* relativePath);
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto)]
private extern static unsafe void RmExecute(void* rm, char* command);
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto)]
private extern static unsafe void* RmGet(void* rm, int type);
[DllImport("Rainmeter.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
private extern static unsafe int LSLog(int type, char* unused, char* message);
private enum RmGetType
{
MeasureName = 0,
Skin = 1,
SettingsFile = 2
}
public enum LogType
{
Error = 1,
Warning = 2,
Notice = 3,
Debug = 4
}
public unsafe string ReadString(string option, string defValue)
{
char* value = RmReadString((void*)m_Rm, ToUnsafe(option), ToUnsafe(defValue), 1);
return new string(value);
}
public unsafe string ReadPath(string option, string defValue)
{
char* relativePath = RmReadString((void*)m_Rm, ToUnsafe(option), ToUnsafe(defValue), 1);
char* value = RmPathToAbsolute((void*)m_Rm, relativePath);
return new string(value);
}
public unsafe double ReadFormula(string option, double defValue)
{
return RmReadFormula((void*)m_Rm, ToUnsafe(option), defValue);
}
public unsafe int ReadInt(string option, int defValue)
{
string value = ReadString(option, "");
return Convert.ToInt32(value);
}
public unsafe string GetMeasureName()
{
char* value = (char*)RmGet((void*)m_Rm, (int)RmGetType.MeasureName);
return new string(value);
}
public unsafe IntPtr GetSkin()
{
return (IntPtr)RmGet((void*)m_Rm, (int)RmGetType.Skin);
}
public static unsafe void Execute(IntPtr skin, string command)
{
RmExecute((void*)skin, ToUnsafe(command));
}
public static unsafe void Log(LogType type, string message)
{
LSLog((int)type, null, ToUnsafe(message));
}
}
/// <summary>
/// Dummy attribute to mark method as exported for DllExporter.exe.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class DllExport : Attribute
{
public DllExport()
{
}
}
}