Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from kodybrown/master
Browse files Browse the repository at this point in the history
Some updates!
  • Loading branch information
DanTup committed Feb 22, 2016
2 parents d547f4a + 2502bee commit 7ec80b3
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 56 deletions.
15 changes: 13 additions & 2 deletions DanTup.BrowserSelector/BrowserSelector.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
; Default browser is first in list
; Micrsoft Edge is a UWP app and requires no path
; Use `{url}` to specify UWP app browser details
[browsers]
chrome = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
ff = C:\Program Files (x86)\Mozilla Firefox\firefox.exe
edge =
edge = microsoft-edge:{url}
ie = iexplore.exe
chrome_prof8 = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 8"

; Url preferences.
; Only * is treated as a special character (wildcard).
Expand All @@ -13,3 +14,13 @@ ie = iexplore.exe
[urls]
microsoft.com = ie
*.microsoft.com = ie

; Use my project-based Chrome profile
myproject.live = chrome_prof8
myproject.local = chrome_prof8

; if the key is wrapped in /'s, it is treated as a regex.
/sites\.google\.com/a/myproject.live\.com/ = chrome_prof8

google.com = chrome
visualstudio.com = edge
56 changes: 55 additions & 1 deletion DanTup.BrowserSelector/ConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace DanTup.BrowserSelector
{
Expand All @@ -11,7 +13,7 @@ static class ConfigReader
/// <summary>
/// Config lives in the same folder as the EXE, name "BrowserSelector.ini".
/// </summary>
static string ConfigPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BrowserSelector.ini");
public static string ConfigPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BrowserSelector.ini");

static internal IEnumerable<UrlPreference> GetUrlPreferences()
{
Expand Down Expand Up @@ -62,6 +64,58 @@ static KeyValuePair<string, string> SplitConfig(string configLine)
var parts = configLine.Split(new[] { '=' }, 2);
return new KeyValuePair<string, string>(parts[0].Trim(), parts[1].Trim());
}

public static void CreateSampleIni()
{
Assembly assembly;
Stream stream;
StringBuilder result;

assembly = Assembly.GetExecutingAssembly();
//stream = assembly.GetManifestResourceStream("DanTup.BrowserSelector.BrowserSelector.ini");
stream = assembly.GetManifestResourceStream(assembly.GetManifestResourceNames()[0]);
if (stream == null)
{
return;
}

result = new StringBuilder();

using (StreamReader reader = new StreamReader(stream))
{
result.Append(reader.ReadToEnd());
reader.Close();
}

if (result.Length > 0)
{
if (File.Exists(ConfigPath))
{
string newName = GetBackupFileName(ConfigPath);
File.Move(ConfigPath, newName);
}

File.WriteAllText(ConfigPath, result.ToString());
}
}

static string GetBackupFileName(string fileName)
{
string newName;
string fname;
string fext;
int index = 0;

fname = Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName);
fext = Path.GetExtension(fileName);

do
{
newName = string.Format("{0}.{1:0000}{2}", fname, ++index, fext);
} while (File.Exists(newName));

return newName;
}
}

class Browser
Expand Down
11 changes: 9 additions & 2 deletions DanTup.BrowserSelector/DanTup.BrowserSelector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<PropertyGroup>
<ApplicationIcon>Browser.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -57,14 +60,18 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="BrowserSelector.ini">
<EmbeddedResource Include="BrowserSelector.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Browser.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</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">
Expand Down
Loading

0 comments on commit 7ec80b3

Please sign in to comment.