Fix HTM config dir handling both on Windows and Unix

This commit is contained in:
Berke Viktor 2012-10-04 14:51:00 +02:00
parent 94c525eee9
commit 723486913f

View File

@ -36,27 +36,45 @@ namespace thememan
{ {
public partial class HTM : Form public partial class HTM : Form
{ {
public string appdata = (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HexChat\\"); public string hexchatdir;
public string home = (Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/.config/hexchat/"); public string themedir;
public string xchatdir;
public string themedir = "themes\\";
OpenFileDialog importDialog; OpenFileDialog importDialog;
public HTM () public HTM ()
{ {
InitializeComponent (); InitializeComponent ();
if (File.Exists ("portable-mode"))
xchatdir = ("config\\");
else if (Directory.Exists (appdata))
xchatdir = (appdata);
else if (Directory.Exists (home)) {
xchatdir = (home); themedir = "themes/";
} else
Console.WriteLine("Install not found");
if (RunningOnWindows() && File.Exists("portable-mode"))
{
hexchatdir = ("config\\");
if (!Directory.Exists(hexchatdir))
{
MessageBox.Show("HexChat installation not found!\nCheck your .\\config folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(1);
}
}
else
{
hexchatdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "hexchat");
if (!Directory.Exists(hexchatdir))
{
if (RunningOnWindows())
{
MessageBox.Show("HexChat installation not found!\nCheck your %APPDATA%\\HexChat folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
MessageBox.Show("HexChat installation not found!\nCheck your ~/.config/hexchat folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Environment.Exit(1);
}
}
themedir = Path.Combine(hexchatdir, "themes");
ListThemes(); ListThemes();
String[] arguments = Environment.GetCommandLineArgs(); String[] arguments = Environment.GetCommandLineArgs();
@ -67,20 +85,32 @@ namespace thememan
} }
} }
private bool RunningOnWindows()
{
if (Environment.OSVersion.ToString().ToLower().Contains("windows"))
{
return true;
}
else
{
return false;
}
}
private void ListThemes() private void ListThemes()
{ {
themelist.Items.Clear(); themelist.Items.Clear();
if (Directory.Exists(xchatdir + themedir)) if (Directory.Exists(themedir))
{ {
foreach (string theme in Directory.GetDirectories(xchatdir + themedir)) foreach (string theme in Directory.GetDirectories(themedir))
{ {
themelist.Items.Add(theme.Remove(0, xchatdir.Length + themedir.Length)); themelist.Items.Add(theme.Remove(0, themedir.Length + 1));
} }
} }
else else
{ {
Directory.CreateDirectory(xchatdir + themedir); Directory.CreateDirectory(themedir);
} }
if (themelist.Items.Count == 0) if (themelist.Items.Count == 0)
@ -122,7 +152,7 @@ namespace thememan
private List<List<string>> ReadTheme(string theme) private List<List<string>> ReadTheme(string theme)
{ {
List<List<string>> themecolors = new List<List<string>>(); List<List<string>> themecolors = new List<List<string>>();
foreach (string line in File.ReadLines(xchatdir + themedir + theme + "/colors.conf")) foreach (string line in File.ReadLines(Path.Combine(themedir, theme, "colors.conf")))
{ {
List<string> colors = new List<string>(); List<string> colors = new List<string>();
List<string> colorlist = new List<string>(); List<string> colorlist = new List<string>();
@ -149,10 +179,10 @@ namespace thememan
DialogResult result = MessageBox.Show("HexChat must be closed and this will overwrite your current theme!\n\nDo you wish to continue?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); DialogResult result = MessageBox.Show("HexChat must be closed and this will overwrite your current theme!\n\nDo you wish to continue?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
File.Copy(xchatdir + themedir + themelist.SelectedItem.ToString() + "\\colors.conf", xchatdir + "colors.conf", true); File.Copy(Path.Combine(themedir, themelist.SelectedItem.ToString(), "colors.conf"), Path.Combine(hexchatdir, "colors.conf"), true);
if (File.Exists(xchatdir + themedir + themelist.SelectedItem.ToString() + "\\pevents.conf")) if (File.Exists(Path.Combine(themedir, themelist.SelectedItem.ToString(), "pevents.conf")))
{ {
File.Copy(xchatdir + themedir + themelist.SelectedItem.ToString() + "\\pevents.conf", xchatdir + "pevents.conf", true); File.Copy(Path.Combine(themedir, themelist.SelectedItem.ToString(), "pevents.conf"), Path.Combine(hexchatdir, "pevents.conf"), true);
} }
} }
} }
@ -242,7 +272,7 @@ namespace thememan
private int extractTheme(FileInfo zipFile) private int extractTheme(FileInfo zipFile)
{ {
string themeName = zipFile.Name.Remove(zipFile.Name.Length - zipFile.Extension.Length); string themeName = zipFile.Name.Remove(zipFile.Name.Length - zipFile.Extension.Length);
string destFolder = xchatdir + themedir + themeName; string destFolder = Path.Combine(themedir, themeName);
try try
{ {
@ -312,7 +342,7 @@ namespace thememan
DialogResult result = MessageBox.Show("Are you sure you want to delete this theme from the theme repo?\n\nYour currently applied theme won't be affected.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); DialogResult result = MessageBox.Show("Are you sure you want to delete this theme from the theme repo?\n\nYour currently applied theme won't be affected.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
Directory.Delete(xchatdir + themedir + themelist.SelectedItem.ToString(), true); Directory.Delete(Path.Combine(themedir, themelist.SelectedItem.ToString()), true);
ListThemes(); ListThemes();
if (themelist.Items.Count == 0) if (themelist.Items.Count == 0)
{ {