commit ebceaedc7b6bf39f1264cc170990711fbb3f3005 Author: BlubbFish Date: Sun Nov 15 22:33:21 2015 +0000 powerswitcher hinzugefügt diff --git a/ConsoleApplication1/App.config b/ConsoleApplication1/App.config new file mode 100644 index 0000000..fad249e --- /dev/null +++ b/ConsoleApplication1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ConsoleApplication1/InIReader.cs b/ConsoleApplication1/InIReader.cs new file mode 100644 index 0000000..720650d --- /dev/null +++ b/ConsoleApplication1/InIReader.cs @@ -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> 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>(); + StreamReader file = new StreamReader(this.filename); + List buf = new List(); + string fline = ""; + while (fline != null) + { + fline = file.ReadLine(); + if (fline != null) + buf.Add(fline); + } + file.Close(); + Dictionary sub = new Dictionary(); + 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(); + } + 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 getSections() + { + return cont.Keys.ToList(); + } + + 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 sub = new Dictionary(); + 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> cap in this.cont) + { + file.WriteLine(cap.Key); + foreach (KeyValuePair sub in cap.Value) + { + file.WriteLine(sub.Key + "=" + sub.Value); + } + file.WriteLine(); + } + file.Flush(); + file.Close(); + } + } +} diff --git a/ConsoleApplication1/PowerSwitcher.csproj b/ConsoleApplication1/PowerSwitcher.csproj new file mode 100644 index 0000000..e7c3836 --- /dev/null +++ b/ConsoleApplication1/PowerSwitcher.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {601C218D-A928-4D96-8068-B54C65934013} + WinExe + Properties + PowerSwitcher + PowerSwitcher + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + Always + + + + + \ No newline at end of file diff --git a/ConsoleApplication1/Program.cs b/ConsoleApplication1/Program.cs new file mode 100644 index 0000000..99910e1 --- /dev/null +++ b/ConsoleApplication1/Program.cs @@ -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 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"; + } + } +} diff --git a/ConsoleApplication1/Properties/AssemblyInfo.cs b/ConsoleApplication1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c13c8c9 --- /dev/null +++ b/ConsoleApplication1/Properties/AssemblyInfo.cs @@ -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")] diff --git a/ConsoleApplication1/bin/Release/PowerSwitcher.exe b/ConsoleApplication1/bin/Release/PowerSwitcher.exe new file mode 100644 index 0000000..4cb2f6f Binary files /dev/null and b/ConsoleApplication1/bin/Release/PowerSwitcher.exe differ diff --git a/ConsoleApplication1/bin/Release/config.ini b/ConsoleApplication1/bin/Release/config.ini new file mode 100644 index 0000000..efa18ee --- /dev/null +++ b/ConsoleApplication1/bin/Release/config.ini @@ -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 + diff --git a/ConsoleApplication1/config.ini b/ConsoleApplication1/config.ini new file mode 100644 index 0000000..156d283 --- /dev/null +++ b/ConsoleApplication1/config.ini @@ -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 \ No newline at end of file diff --git a/PowerSwitcher.sln b/PowerSwitcher.sln new file mode 100644 index 0000000..07115d3 --- /dev/null +++ b/PowerSwitcher.sln @@ -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