From ebceaedc7b6bf39f1264cc170990711fbb3f3005 Mon Sep 17 00:00:00 2001 From: BlubbFish Date: Sun, 15 Nov 2015 22:33:21 +0000 Subject: [PATCH] =?UTF-8?q?powerswitcher=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleApplication1/App.config | 6 + ConsoleApplication1/InIReader.cs | 142 ++++++++++++++++++ ConsoleApplication1/PowerSwitcher.csproj | 69 +++++++++ ConsoleApplication1/Program.cs | 89 +++++++++++ .../Properties/AssemblyInfo.cs | 38 +++++ .../bin/Release/PowerSwitcher.exe | Bin 0 -> 9728 bytes ConsoleApplication1/bin/Release/config.ini | 13 ++ ConsoleApplication1/config.ini | 12 ++ PowerSwitcher.sln | 20 +++ 9 files changed, 389 insertions(+) create mode 100644 ConsoleApplication1/App.config create mode 100644 ConsoleApplication1/InIReader.cs create mode 100644 ConsoleApplication1/PowerSwitcher.csproj create mode 100644 ConsoleApplication1/Program.cs create mode 100644 ConsoleApplication1/Properties/AssemblyInfo.cs create mode 100644 ConsoleApplication1/bin/Release/PowerSwitcher.exe create mode 100644 ConsoleApplication1/bin/Release/config.ini create mode 100644 ConsoleApplication1/config.ini create mode 100644 PowerSwitcher.sln 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 0000000000000000000000000000000000000000..4cb2f6f3f65c70c459c0df119a289ae49c7b33e5 GIT binary patch literal 9728 zcmeHMeQ;dWbw77M-mX^i;$7Ji#$V5pF^goaC0l@PEUZt_N!uYaZ5rBXCZtT6Hth`Q zP}ASJ@2#}5fzs(e%}k&4&OKlEoO93pe0PuB^EnCAvnICPH$5># zG%AAh%-o+Ht$O=01w_55C)xx~)Z>obj#9_li6E%Q-ai14Xt>`0heK~Zc76pB{rb5~^7hKSj8v!6w zZS~^@r5>GVI&C|47LJE%Y9x$_0H=OAtxD-*fM92k{ir99N)p9vK~#2NGWGys3I$T@fChpOVAO>I z_bb*F4Ta{chd?&5GzFp7w#6?uc7|v#tl&QpaGKc?P*i3U&h?;U&IZ7GdktJQv?nxq z1IUKx&PXIGk>FUg<84i1G{v0F0Be+9V<;k#$XH|D-p3GbvM#lisc<4}Uk5YIDV<3T z#-y2{`sS&3DP0m=~=}L=sV%0*>fzMzR0I`|rR1qj<9JN>hkvqih53Z$3_7 zZ35FEK$G-rSj4$=4tasgc34QE3GFb&eK*ZQJVAQ^!OISaJCX_y+QZzOG&pNTP3>R` zo!7o|r^gD)PAJGOfRHC>tQCahZb;hJwKc-mx8VnM6aQmh1GOe=eXXw*gu-$UoV9me z#pHapZ&ckB)1bt(ucE15^hV`6+0BAf1Vhmqh#xXq+jx9_pL53J(;JkxplVE$x1wk| zBX2|D5pwS`+H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