powerswitcher hinzugefügt
This commit is contained in:
commit
ebceaedc7b
6
ConsoleApplication1/App.config
Normal file
6
ConsoleApplication1/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
142
ConsoleApplication1/InIReader.cs
Normal file
142
ConsoleApplication1/InIReader.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PowerSwitcher
|
||||
{
|
||||
public class InIReader
|
||||
{
|
||||
private Dictionary<string,Dictionary<string,string>> cont;
|
||||
private FileSystemWatcher k = new FileSystemWatcher(Directory.GetCurrentDirectory(), "*.ini");
|
||||
private string filename;
|
||||
|
||||
public InIReader(string filename)
|
||||
{
|
||||
this.filename = filename;
|
||||
k.Changed += new FileSystemEventHandler(this.readAgain);
|
||||
loadFile();
|
||||
}
|
||||
|
||||
private void readAgain(object sender, EventArgs e)
|
||||
{
|
||||
loadFile();
|
||||
}
|
||||
|
||||
private void loadFile()
|
||||
{
|
||||
this.cont = new Dictionary<string, Dictionary<string, string>>();
|
||||
StreamReader file = new StreamReader(this.filename);
|
||||
List<String> buf = new List<string>();
|
||||
string fline = "";
|
||||
while (fline != null)
|
||||
{
|
||||
fline = file.ReadLine();
|
||||
if (fline != null)
|
||||
buf.Add(fline);
|
||||
}
|
||||
file.Close();
|
||||
Dictionary<string, string> sub = new Dictionary<string, string>();
|
||||
string cap = "";
|
||||
foreach (string line in buf)
|
||||
{
|
||||
Match match = Regex.Match(line, @"^\[[a-zA-Z0-9\-_ ]+\]\w*$", RegexOptions.IgnoreCase);
|
||||
if (match.Success)
|
||||
{
|
||||
if (sub.Count != 0 && cap != "")
|
||||
{
|
||||
cont.Add(cap, sub);
|
||||
}
|
||||
cap = line;
|
||||
sub = new Dictionary<string, string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (line != "" && cap != "")
|
||||
{
|
||||
string key = line.Substring(0,line.IndexOf('='));
|
||||
string value = line.Substring(line.IndexOf('=')+1);
|
||||
sub.Add(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sub.Count != 0 && cap != "")
|
||||
{
|
||||
cont.Add(cap, sub);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getSections()
|
||||
{
|
||||
return cont.Keys.ToList<String>();
|
||||
}
|
||||
|
||||
public String getValue(String section, String key)
|
||||
{
|
||||
if (!section.StartsWith("["))
|
||||
{
|
||||
section = "[" + section + "]";
|
||||
}
|
||||
if (cont.Keys.Contains(section))
|
||||
{
|
||||
if (cont[section].Keys.Contains(key))
|
||||
{
|
||||
return cont[section][key];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void SetValue(string section, string key, string value)
|
||||
{
|
||||
if (!section.StartsWith("["))
|
||||
{
|
||||
section = "[" + section + "]";
|
||||
}
|
||||
if (cont.Keys.Contains(section))
|
||||
{
|
||||
if (cont[section].Keys.Contains(key))
|
||||
{
|
||||
cont[section][key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
cont[section].Add(key, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string,string> sub = new Dictionary<string,string>();
|
||||
sub.Add(key, value);
|
||||
cont.Add(section, sub);
|
||||
}
|
||||
k.Changed -= null;
|
||||
saveSettings();
|
||||
loadFile();
|
||||
k.Changed += new FileSystemEventHandler(this.readAgain);
|
||||
}
|
||||
|
||||
private void saveSettings()
|
||||
{
|
||||
StreamWriter file = new StreamWriter(this.filename);
|
||||
file.BaseStream.SetLength(0);
|
||||
file.BaseStream.Flush();
|
||||
file.BaseStream.Seek(0, SeekOrigin.Begin);
|
||||
foreach (KeyValuePair<string, Dictionary<string, string>> cap in this.cont)
|
||||
{
|
||||
file.WriteLine(cap.Key);
|
||||
foreach (KeyValuePair<string, string> sub in cap.Value)
|
||||
{
|
||||
file.WriteLine(sub.Key + "=" + sub.Value);
|
||||
}
|
||||
file.WriteLine();
|
||||
}
|
||||
file.Flush();
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
69
ConsoleApplication1/PowerSwitcher.csproj
Normal file
69
ConsoleApplication1/PowerSwitcher.csproj
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{601C218D-A928-4D96-8068-B54C65934013}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PowerSwitcher</RootNamespace>
|
||||
<AssemblyName>PowerSwitcher</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="InIReader.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="config.ini">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- 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>
|
89
ConsoleApplication1/Program.cs
Normal file
89
ConsoleApplication1/Program.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace PowerSwitcher
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static NotifyIcon trayi = new NotifyIcon();
|
||||
private static InIReader ini;
|
||||
static void Main(string[] args)
|
||||
{
|
||||
init();
|
||||
toogle();
|
||||
remove();
|
||||
}
|
||||
|
||||
private static void remove()
|
||||
{
|
||||
trayi.Visible = false;
|
||||
}
|
||||
|
||||
private static void toogle()
|
||||
{
|
||||
List<String> all = ini.getSections();
|
||||
all.Remove("[Application]");
|
||||
all.Remove("[" + ini.getValue("Application", "lastused") + "]");
|
||||
String profile = all.ElementAt(0).Substring(1);
|
||||
profile = profile.Substring(0, profile.Length - 1);
|
||||
|
||||
showTooltip("Profil:", profile, ToolTipIcon.Info);
|
||||
|
||||
runProgram(ini.getValue("Application", "graphicexe"), ini.getValue(profile, "graphic"));
|
||||
showTooltip("Neue Einstelllung", "Grafikkartengeschwindigkeit", ToolTipIcon.Info);
|
||||
|
||||
runProgram(ini.getValue("Application", "pwcfgexe"), ini.getValue(profile, "pwcfg"));
|
||||
showTooltip("Neue Einstelllung", "CPU Geschwindigkeit", ToolTipIcon.Info);
|
||||
|
||||
ini.SetValue("Application", "lastused", profile);
|
||||
|
||||
System.Threading.Thread.Sleep(5000);
|
||||
}
|
||||
|
||||
private static void runProgram(string prog, string args)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.Arguments = args;
|
||||
p.StartInfo.FileName = prog;
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.Start();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
}
|
||||
|
||||
private static void showTooltip(string title, string text, ToolTipIcon toolTipIcon)
|
||||
{
|
||||
trayi.BalloonTipIcon = toolTipIcon;
|
||||
trayi.BalloonTipText = text;
|
||||
trayi.BalloonTipTitle = title;
|
||||
trayi.ShowBalloonTip(100);
|
||||
}
|
||||
|
||||
private static void init()
|
||||
{
|
||||
setIcon();
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
private static void loadConfig()
|
||||
{
|
||||
ini = new InIReader("config.ini");
|
||||
}
|
||||
|
||||
private static void setIcon()
|
||||
{
|
||||
trayi.Visible = true;
|
||||
trayi.Icon = new Icon(SystemIcons.WinLogo, 40, 40);
|
||||
trayi.Text = "PowerSwitcher";
|
||||
}
|
||||
}
|
||||
}
|
38
ConsoleApplication1/Properties/AssemblyInfo.cs
Normal file
38
ConsoleApplication1/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("PowerSwitcher")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("bb02b006-85c2-4059-93a4-6fb151091d38")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("de-DE")]
|
BIN
ConsoleApplication1/bin/Release/PowerSwitcher.exe
Normal file
BIN
ConsoleApplication1/bin/Release/PowerSwitcher.exe
Normal file
Binary file not shown.
13
ConsoleApplication1/bin/Release/config.ini
Normal file
13
ConsoleApplication1/bin/Release/config.ini
Normal file
@ -0,0 +1,13 @@
|
||||
[Application]
|
||||
lastused=Full Power
|
||||
graphicexe=C:\Program Files (x86)\ThinkPad\Utilities\PWMUIAux.EXE
|
||||
pwcfgexe=powercfg
|
||||
|
||||
[Full Power]
|
||||
graphic=/HighPerformanceGpu
|
||||
pwcfg=-S c6d5e384-54a1-46f5-a8b7-8fbb87e7a2dd
|
||||
|
||||
[Energie Save]
|
||||
graphic=/EnergySavingGpu
|
||||
pwcfg=-S 5478d100-1bf9-4080-97ad-dfb8950a2686
|
||||
|
12
ConsoleApplication1/config.ini
Normal file
12
ConsoleApplication1/config.ini
Normal file
@ -0,0 +1,12 @@
|
||||
[Application]
|
||||
lastused=Full Power
|
||||
graphicexe=C:\Program Files (x86)\ThinkPad\Utilities\PWMUIAux.EXE
|
||||
pwcfgexe=powercfg
|
||||
|
||||
[Full Power]
|
||||
graphic=/HighPerformanceGpu
|
||||
pwcfg=-S c6d5e384-54a1-46f5-a8b7-8fbb87e7a2dd
|
||||
|
||||
[Energie Save]
|
||||
graphic=/EnergySavingGpu
|
||||
pwcfg=-S 5478d100-1bf9-4080-97ad-dfb8950a2686
|
20
PowerSwitcher.sln
Normal file
20
PowerSwitcher.sln
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PowerSwitcher", "ConsoleApplication1\PowerSwitcher.csproj", "{601C218D-A928-4D96-8068-B54C65934013}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{601C218D-A928-4D96-8068-B54C65934013}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{601C218D-A928-4D96-8068-B54C65934013}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{601C218D-A928-4D96-8068-B54C65934013}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{601C218D-A928-4D96-8068-B54C65934013}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user