Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ability to select assemblies to reference if more than 1
* add logic to ensure correct target framework folder is selected, if present
- Loading branch information
Kiliman
committed
Aug 9, 2010
1 parent
a566197
commit b410684
Showing
16 changed files
with
692 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,72 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace NuForVS.Core | ||
{ | ||
public class ConfigurationManager : IConfigurationManager | ||
{ | ||
private string _configPath; | ||
private Configuration _config = new Configuration(); | ||
|
||
public ConfigurationManager() | ||
{ | ||
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NuForVS"); | ||
if (!Directory.Exists(path)) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
|
||
_configPath = Path.Combine(path, "config.ini"); | ||
|
||
if (!File.Exists(_configPath)) | ||
{ | ||
// copy default config from resource | ||
using (var sr = new StreamReader(this.GetType().Assembly.GetManifestResourceStream("NuForVS.Resources.config.ini"))) | ||
{ | ||
File.WriteAllText(_configPath, sr.ReadToEnd()); | ||
} | ||
} | ||
|
||
loadConfig(); | ||
} | ||
|
||
private void loadConfig() | ||
{ | ||
var ini = new IniFile(_configPath); | ||
_config.GemCommand = ini.ReadValue("general", "gemCommand"); | ||
_config.GemServer = ini.ReadValue("general", "gemServer"); | ||
_config.AutoReferences.Clear(); | ||
|
||
var references = ini.GetSection("auto-reference"); | ||
foreach (var item in references) | ||
{ | ||
var part = item.Split('='); | ||
var autoRef = new AutoReference {GemName = part[0]}; | ||
var assemblies = part[1]; | ||
foreach (var path in assemblies.Split(',')) | ||
{ | ||
autoRef.Assemblies.Add(path); | ||
} | ||
_config.AutoReferences.Add(autoRef); | ||
} | ||
} | ||
|
||
public string ConfigurationAsText | ||
{ | ||
get { return File.ReadAllText(_configPath); } | ||
} | ||
public Configuration GetConfig() | ||
{ | ||
return new Configuration(); | ||
return _config; | ||
} | ||
|
||
public void SaveConfig(string configText) | ||
{ | ||
File.WriteAllText(_configPath, configText); | ||
loadConfig(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace NuForVS.Core | ||
{ | ||
public class IniFile | ||
{ | ||
private string _path; | ||
|
||
[DllImport("kernel32")] | ||
private static extern long WritePrivateProfileString(string section, | ||
string key, string val, string filePath); | ||
[DllImport("kernel32")] | ||
private static extern int GetPrivateProfileString(string section, | ||
string key, string def, StringBuilder retVal, | ||
int size, string filePath); | ||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] | ||
static extern uint GetPrivateProfileSection(string lpAppName, | ||
IntPtr lpReturnedString, uint nSize, string lpFileName); | ||
|
||
public IniFile(string path) | ||
{ | ||
_path = path; | ||
} | ||
|
||
public void WriteValue(string section, string key, string value) | ||
{ | ||
WritePrivateProfileString(section, key, value, _path); | ||
} | ||
|
||
public string ReadValue(string section, string key) | ||
{ | ||
var sb = new StringBuilder(255); | ||
var i = GetPrivateProfileString(section, key, "", sb, sb.Capacity, _path); | ||
return sb.ToString(); | ||
} | ||
|
||
public string[] GetSection(string section) | ||
{ | ||
var items = new string[0]; | ||
|
||
if (!System.IO.File.Exists(_path)) | ||
return items; | ||
|
||
uint MAX_BUFFER = 32767; | ||
|
||
IntPtr pReturnedString = Marshal.AllocCoTaskMem((int)MAX_BUFFER); | ||
|
||
uint bytesReturned = GetPrivateProfileSection(section, pReturnedString, MAX_BUFFER, _path); | ||
|
||
if ((bytesReturned == MAX_BUFFER - 2) || (bytesReturned == 0)) | ||
{ | ||
Marshal.FreeCoTaskMem(pReturnedString); | ||
return items; | ||
} | ||
|
||
//bytesReturned -1 to remove trailing \0 | ||
|
||
// NOTE: Calling Marshal.PtrToStringAuto(pReturnedString) will | ||
// result in only the first pair being returned | ||
string returnedString = Marshal.PtrToStringAuto(pReturnedString, (int)bytesReturned - 1); | ||
|
||
items = returnedString.Split('\0'); | ||
|
||
Marshal.FreeCoTaskMem(pReturnedString); | ||
return items; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.