Added personal folder path setting to Settings form which can edit PersonalPath.cfg

This commit is contained in:
Jaex 2013-12-11 20:36:23 +02:00
parent 7c11cc37bb
commit 16ea432263
7 changed files with 200 additions and 71 deletions

View file

@ -371,14 +371,19 @@ public static string URLPathEncode(string text)
return Encode(text, URLPathCharacters);
}
public static bool OpenFolder(string folderPath)
public static void OpenFolder(string folderPath)
{
if (!string.IsNullOrEmpty(folderPath) && Directory.Exists(folderPath))
if (!string.IsNullOrEmpty(folderPath))
{
Process.Start("explorer.exe", folderPath);
return true;
if (Directory.Exists(folderPath))
{
Process.Start("explorer.exe", folderPath);
}
else
{
MessageBox.Show("Folder not exist:\r\n" + folderPath, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
return false;
}
public static void OpenFolderWithFile(string filePath)

View file

@ -40,32 +40,6 @@ public abstract class SettingsBase<T> where T : SettingsBase<T>, new()
[Browsable(false), XmlIgnore, JsonIgnore]
public string FilePath { get; private set; }
public virtual bool Save(string filePath)
{
FilePath = filePath;
return SettingsHelper.Save(this, filePath, SerializationType);
}
public void Save()
{
Save(FilePath);
}
public void SaveAsync(string filePath)
{
ThreadPool.QueueUserWorkItem(state => Save(filePath));
}
public void SaveAsync()
{
SaveAsync(FilePath);
}
public virtual void Save(Stream stream)
{
SettingsHelper.Save(this, stream, SerializationType);
}
public static T Load(string filePath)
{
T setting = SettingsHelper.Load<T>(filePath, SerializationType);
@ -78,5 +52,31 @@ public static T Load(Stream stream)
T setting = SettingsHelper.Load<T>(stream, SerializationType);
return setting;
}
public virtual bool Save(string filePath)
{
FilePath = filePath;
return SettingsHelper.Save(this, filePath, SerializationType);
}
private void Save()
{
Save(FilePath);
}
public void SaveAsync(string filePath)
{
ThreadPool.QueueUserWorkItem(state => Save(filePath));
}
private void SaveAsync()
{
SaveAsync(FilePath);
}
public virtual void Save(Stream stream)
{
SettingsHelper.Save(this, stream, SerializationType);
}
}
}

View file

@ -89,7 +89,7 @@ private void pbDana_Click(object sender, EventArgs e)
private void rtb_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
Helpers.LoadBrowserAsync(e.LinkText);
}
#region Animation

View file

@ -606,7 +606,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
Hide();
Program.Settings.SaveAsync();
Program.Settings.SaveAsync(Program.ApplicationConfigFilePath);
}
}
@ -705,7 +705,7 @@ private void tsbApplicationSettings_Click(object sender, EventArgs e)
}
AfterSettingsJobs();
Program.Settings.SaveAsync();
Program.Settings.SaveAsync(Program.ApplicationConfigFilePath);
}
private void tsbTaskSettings_Click(object sender, EventArgs e)
@ -715,7 +715,7 @@ private void tsbTaskSettings_Click(object sender, EventArgs e)
taskSettingsForm.ShowDialog();
}
Program.Settings.SaveAsync();
Program.Settings.SaveAsync(Program.ApplicationConfigFilePath);
}
private void tsbHotkeySettings_Click(object sender, EventArgs e)
@ -730,7 +730,7 @@ private void tsbHotkeySettings_Click(object sender, EventArgs e)
hotkeySettingsForm.ShowDialog();
}
Program.HotkeysConfig.SaveAsync();
Program.HotkeysConfig.SaveAsync(Program.HotkeysConfigFilePath);
}
private void tsbDestinationSettings_Click(object sender, EventArgs e)
@ -770,10 +770,7 @@ private void tsmiImageEffects_Click(object sender, EventArgs e)
private void tsbScreenshotsFolder_Click(object sender, EventArgs e)
{
if (!Helpers.OpenFolder(Program.ScreenshotsPath))
{
Helpers.OpenFolder(Program.ScreenshotsParentFolder);
}
Helpers.OpenFolder(Program.ScreenshotsPath);
}
private void tsbHistory_Click(object sender, EventArgs e)

View file

@ -39,8 +39,13 @@ private void InitializeComponent()
this.cbShowTray = new System.Windows.Forms.CheckBox();
this.cbSendToMenu = new System.Windows.Forms.CheckBox();
this.tpPaths = new System.Windows.Forms.TabPage();
this.btnOpenScreenshotsFolder = new System.Windows.Forms.Button();
this.lblPreviewPersonalFolderPath = new System.Windows.Forms.Label();
this.btnBrowsePersonalFolderPath = new System.Windows.Forms.Button();
this.lblPersonalFolderPath = new System.Windows.Forms.Label();
this.txtPersonalFolderPath = new System.Windows.Forms.TextBox();
this.btnBrowseCustomScreenshotsPath = new System.Windows.Forms.Button();
this.btnOpenPersonalFolder = new System.Windows.Forms.Button();
this.btnOpenPersonalFolderPath = new System.Windows.Forms.Button();
this.txtCustomScreenshotsPath = new System.Windows.Forms.TextBox();
this.cbUseCustomScreenshotsPath = new System.Windows.Forms.CheckBox();
this.lblSaveImageSubFolderPattern = new System.Windows.Forms.Label();
@ -216,8 +221,13 @@ private void InitializeComponent()
//
// tpPaths
//
this.tpPaths.Controls.Add(this.btnOpenScreenshotsFolder);
this.tpPaths.Controls.Add(this.lblPreviewPersonalFolderPath);
this.tpPaths.Controls.Add(this.btnBrowsePersonalFolderPath);
this.tpPaths.Controls.Add(this.lblPersonalFolderPath);
this.tpPaths.Controls.Add(this.txtPersonalFolderPath);
this.tpPaths.Controls.Add(this.btnBrowseCustomScreenshotsPath);
this.tpPaths.Controls.Add(this.btnOpenPersonalFolder);
this.tpPaths.Controls.Add(this.btnOpenPersonalFolderPath);
this.tpPaths.Controls.Add(this.txtCustomScreenshotsPath);
this.tpPaths.Controls.Add(this.cbUseCustomScreenshotsPath);
this.tpPaths.Controls.Add(this.lblSaveImageSubFolderPattern);
@ -231,9 +241,55 @@ private void InitializeComponent()
this.tpPaths.Text = "Paths";
this.tpPaths.UseVisualStyleBackColor = true;
//
// btnOpenScreenshotsFolder
//
this.btnOpenScreenshotsFolder.Location = new System.Drawing.Point(16, 184);
this.btnOpenScreenshotsFolder.Name = "btnOpenScreenshotsFolder";
this.btnOpenScreenshotsFolder.Size = new System.Drawing.Size(80, 23);
this.btnOpenScreenshotsFolder.TabIndex = 18;
this.btnOpenScreenshotsFolder.Text = "Open...";
this.btnOpenScreenshotsFolder.UseVisualStyleBackColor = true;
this.btnOpenScreenshotsFolder.Click += new System.EventHandler(this.btnOpenScreenshotsFolder_Click);
//
// lblPreviewPersonalFolderPath
//
this.lblPreviewPersonalFolderPath.AutoSize = true;
this.lblPreviewPersonalFolderPath.Location = new System.Drawing.Point(104, 69);
this.lblPreviewPersonalFolderPath.Name = "lblPreviewPersonalFolderPath";
this.lblPreviewPersonalFolderPath.Size = new System.Drawing.Size(16, 13);
this.lblPreviewPersonalFolderPath.TabIndex = 17;
this.lblPreviewPersonalFolderPath.Text = "...";
//
// btnBrowsePersonalFolderPath
//
this.btnBrowsePersonalFolderPath.Location = new System.Drawing.Point(432, 39);
this.btnBrowsePersonalFolderPath.Name = "btnBrowsePersonalFolderPath";
this.btnBrowsePersonalFolderPath.Size = new System.Drawing.Size(80, 23);
this.btnBrowsePersonalFolderPath.TabIndex = 16;
this.btnBrowsePersonalFolderPath.Text = "Browse...";
this.btnBrowsePersonalFolderPath.UseVisualStyleBackColor = true;
this.btnBrowsePersonalFolderPath.Click += new System.EventHandler(this.btnBrowsePersonalFolderPath_Click);
//
// lblPersonalFolderPath
//
this.lblPersonalFolderPath.AutoSize = true;
this.lblPersonalFolderPath.Location = new System.Drawing.Point(16, 16);
this.lblPersonalFolderPath.Name = "lblPersonalFolderPath";
this.lblPersonalFolderPath.Size = new System.Drawing.Size(117, 13);
this.lblPersonalFolderPath.TabIndex = 15;
this.lblPersonalFolderPath.Text = "ShareX personal folder:";
//
// txtPersonalFolderPath
//
this.txtPersonalFolderPath.Location = new System.Drawing.Point(16, 40);
this.txtPersonalFolderPath.Name = "txtPersonalFolderPath";
this.txtPersonalFolderPath.Size = new System.Drawing.Size(408, 20);
this.txtPersonalFolderPath.TabIndex = 14;
this.txtPersonalFolderPath.TextChanged += new System.EventHandler(this.txtPersonalFolderPath_TextChanged);
//
// btnBrowseCustomScreenshotsPath
//
this.btnBrowseCustomScreenshotsPath.Location = new System.Drawing.Point(432, 191);
this.btnBrowseCustomScreenshotsPath.Location = new System.Drawing.Point(432, 127);
this.btnBrowseCustomScreenshotsPath.Name = "btnBrowseCustomScreenshotsPath";
this.btnBrowseCustomScreenshotsPath.Size = new System.Drawing.Size(80, 23);
this.btnBrowseCustomScreenshotsPath.TabIndex = 10;
@ -241,19 +297,19 @@ private void InitializeComponent()
this.btnBrowseCustomScreenshotsPath.UseVisualStyleBackColor = true;
this.btnBrowseCustomScreenshotsPath.Click += new System.EventHandler(this.btnBrowseCustomScreenshotsPath_Click);
//
// btnOpenPersonalFolder
// btnOpenPersonalFolderPath
//
this.btnOpenPersonalFolder.Location = new System.Drawing.Point(16, 16);
this.btnOpenPersonalFolder.Name = "btnOpenPersonalFolder";
this.btnOpenPersonalFolder.Size = new System.Drawing.Size(176, 23);
this.btnOpenPersonalFolder.TabIndex = 0;
this.btnOpenPersonalFolder.Text = "Open ShareX personal folder";
this.btnOpenPersonalFolder.UseVisualStyleBackColor = true;
this.btnOpenPersonalFolder.Click += new System.EventHandler(this.btnOpenPersonalFolder_Click);
this.btnOpenPersonalFolderPath.Location = new System.Drawing.Point(16, 64);
this.btnOpenPersonalFolderPath.Name = "btnOpenPersonalFolderPath";
this.btnOpenPersonalFolderPath.Size = new System.Drawing.Size(80, 23);
this.btnOpenPersonalFolderPath.TabIndex = 0;
this.btnOpenPersonalFolderPath.Text = "Open...";
this.btnOpenPersonalFolderPath.UseVisualStyleBackColor = true;
this.btnOpenPersonalFolderPath.Click += new System.EventHandler(this.btnOpenPersonalFolder_Click);
//
// txtCustomScreenshotsPath
//
this.txtCustomScreenshotsPath.Location = new System.Drawing.Point(16, 192);
this.txtCustomScreenshotsPath.Location = new System.Drawing.Point(16, 128);
this.txtCustomScreenshotsPath.Name = "txtCustomScreenshotsPath";
this.txtCustomScreenshotsPath.Size = new System.Drawing.Size(408, 20);
this.txtCustomScreenshotsPath.TabIndex = 9;
@ -262,7 +318,7 @@ private void InitializeComponent()
// cbUseCustomScreenshotsPath
//
this.cbUseCustomScreenshotsPath.AutoSize = true;
this.cbUseCustomScreenshotsPath.Location = new System.Drawing.Point(16, 168);
this.cbUseCustomScreenshotsPath.Location = new System.Drawing.Point(16, 104);
this.cbUseCustomScreenshotsPath.Name = "cbUseCustomScreenshotsPath";
this.cbUseCustomScreenshotsPath.Size = new System.Drawing.Size(174, 17);
this.cbUseCustomScreenshotsPath.TabIndex = 8;
@ -273,7 +329,7 @@ private void InitializeComponent()
// lblSaveImageSubFolderPattern
//
this.lblSaveImageSubFolderPattern.AutoSize = true;
this.lblSaveImageSubFolderPattern.Location = new System.Drawing.Point(16, 224);
this.lblSaveImageSubFolderPattern.Location = new System.Drawing.Point(16, 160);
this.lblSaveImageSubFolderPattern.Name = "lblSaveImageSubFolderPattern";
this.lblSaveImageSubFolderPattern.Size = new System.Drawing.Size(94, 13);
this.lblSaveImageSubFolderPattern.TabIndex = 11;
@ -282,7 +338,7 @@ private void InitializeComponent()
// lblSaveImageSubFolderPatternPreview
//
this.lblSaveImageSubFolderPatternPreview.AutoSize = true;
this.lblSaveImageSubFolderPatternPreview.Location = new System.Drawing.Point(16, 248);
this.lblSaveImageSubFolderPatternPreview.Location = new System.Drawing.Point(104, 189);
this.lblSaveImageSubFolderPatternPreview.Name = "lblSaveImageSubFolderPatternPreview";
this.lblSaveImageSubFolderPatternPreview.Size = new System.Drawing.Size(16, 13);
this.lblSaveImageSubFolderPatternPreview.TabIndex = 13;
@ -290,9 +346,9 @@ private void InitializeComponent()
//
// txtSaveImageSubFolderPattern
//
this.txtSaveImageSubFolderPattern.Location = new System.Drawing.Point(120, 220);
this.txtSaveImageSubFolderPattern.Location = new System.Drawing.Point(120, 156);
this.txtSaveImageSubFolderPattern.Name = "txtSaveImageSubFolderPattern";
this.txtSaveImageSubFolderPattern.Size = new System.Drawing.Size(304, 20);
this.txtSaveImageSubFolderPattern.Size = new System.Drawing.Size(392, 20);
this.txtSaveImageSubFolderPattern.TabIndex = 12;
this.txtSaveImageSubFolderPattern.TextChanged += new System.EventHandler(this.txtSaveImageSubFolderPattern_TextChanged);
//
@ -669,6 +725,7 @@ private void InitializeComponent()
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - Settings";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.SettingsForm_FormClosed);
this.Shown += new System.EventHandler(this.SettingsForm_Shown);
this.Resize += new System.EventHandler(this.SettingsForm_Resize);
this.tcSettings.ResumeLayout(false);
@ -698,7 +755,7 @@ private void InitializeComponent()
private System.Windows.Forms.TabPage tpGeneral;
private System.Windows.Forms.TabPage tpProxy;
private System.Windows.Forms.CheckBox cbSendToMenu;
private System.Windows.Forms.Button btnOpenPersonalFolder;
private System.Windows.Forms.Button btnOpenPersonalFolderPath;
private System.Windows.Forms.CheckBox cbShowTray;
private System.Windows.Forms.CheckBox cbStartWithWindows;
private System.Windows.Forms.Label lblSaveImageSubFolderPatternPreview;
@ -746,5 +803,10 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox cbTaskbarProgressEnabled;
private System.Windows.Forms.CheckBox cbTrayIconProgressEnabled;
private System.Windows.Forms.CheckBox cbRememberMainFormSize;
private System.Windows.Forms.Label lblPreviewPersonalFolderPath;
private System.Windows.Forms.Button btnBrowsePersonalFolderPath;
private System.Windows.Forms.Label lblPersonalFolderPath;
private System.Windows.Forms.TextBox txtPersonalFolderPath;
private System.Windows.Forms.Button btnOpenScreenshotsFolder;
}
}

View file

@ -66,6 +66,8 @@ private void LoadSettings()
cbRememberMainFormSize.Checked = Program.Settings.RememberMainFormSize;
// Paths
txtPersonalFolderPath.Text = Program.ReadPersonalPathConfig();
UpdatePersonalFolderPathPreview();
cbUseCustomScreenshotsPath.Checked = Program.Settings.UseCustomScreenshotsPath;
txtCustomScreenshotsPath.Text = Program.Settings.CustomScreenshotsPath;
txtSaveImageSubFolderPattern.Text = Program.Settings.SaveImageSubFolderPattern;
@ -117,6 +119,11 @@ private void SettingsForm_Resize(object sender, EventArgs e)
Refresh();
}
private void SettingsForm_FormClosed(object sender, FormClosedEventArgs e)
{
Program.WritePersonalPathConfig(txtPersonalFolderPath.Text);
}
private void UpdateProxyControls()
{
switch (Program.Settings.ProxySettings.ProxyMethod)
@ -134,6 +141,22 @@ private void UpdateProxyControls()
}
}
private void UpdatePersonalFolderPathPreview()
{
string personalPath = txtPersonalFolderPath.Text;
if (string.IsNullOrEmpty(personalPath))
{
personalPath = Program.DefaultPersonalPath;
}
else
{
personalPath = Path.GetFullPath(personalPath);
}
lblPreviewPersonalFolderPath.Text = personalPath;
}
#region General
private void cbShowTray_CheckedChanged(object sender, EventArgs e)
@ -200,12 +223,19 @@ private void cbRememberMainFormSize_CheckedChanged(object sender, EventArgs e)
#region Paths
private void txtPersonalFolderPath_TextChanged(object sender, EventArgs e)
{
UpdatePersonalFolderPathPreview();
}
private void btnBrowsePersonalFolderPath_Click(object sender, EventArgs e)
{
Helpers.BrowseFolder("Choose ShareX personal folder path", txtPersonalFolderPath, Program.PersonalPath);
}
private void btnOpenPersonalFolder_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(Program.PersonalPath) && Directory.Exists(Program.PersonalPath))
{
Process.Start(Program.PersonalPath);
}
Helpers.OpenFolder(lblPreviewPersonalFolderPath.Text);
}
private void cbUseCustomScreenshotsPath_CheckedChanged(object sender, EventArgs e)
@ -231,6 +261,11 @@ private void txtSaveImageSubFolderPattern_TextChanged(object sender, EventArgs e
lblSaveImageSubFolderPatternPreview.Text = Program.ScreenshotsPath;
}
private void btnOpenScreenshotsFolder_Click(object sender, EventArgs e)
{
Helpers.OpenFolder(lblSaveImageSubFolderPatternPreview.Text);
}
#endregion Paths
#region Proxy

View file

@ -71,7 +71,7 @@ public static string AssemblyCopyright
public static readonly string StartupPath = Application.StartupPath;
private static readonly string DefaultPersonalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ApplicationName);
public static readonly string DefaultPersonalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ApplicationName);
private static readonly string PortablePersonalPath = Path.Combine(StartupPath, ApplicationName);
private static readonly string PersonalPathConfig = Path.Combine(StartupPath, "PersonalPath.cfg");
private static readonly string ApplicationConfigFilename = "ApplicationConfig.json";
@ -351,20 +351,50 @@ public static void BackupSettings()
}
private static void CheckPersonalPathConfig()
{
string customPersonalPath = ReadPersonalPathConfig();
if (!string.IsNullOrEmpty(customPersonalPath))
{
CustomPersonalPath = Path.GetFullPath(customPersonalPath);
if (CustomPersonalPath.Equals(PortablePersonalPath, StringComparison.InvariantCultureIgnoreCase))
{
IsPortable = true;
}
}
}
public static string ReadPersonalPathConfig()
{
if (File.Exists(PersonalPathConfig))
{
string customPersonalPath = File.ReadAllText(PersonalPathConfig, Encoding.UTF8).Trim();
return File.ReadAllText(PersonalPathConfig, Encoding.UTF8).Trim();
}
if (!string.IsNullOrEmpty(customPersonalPath))
return string.Empty;
}
public static void WritePersonalPathConfig(string path)
{
// If path is empty and config file is not exist then don't create it
if (!string.IsNullOrEmpty(path) || File.Exists(PersonalPathConfig))
{
File.WriteAllText(PersonalPathConfig, path ?? string.Empty, Encoding.UTF8);
CustomPersonalPath = Path.GetFullPath(path);
if (CustomPersonalPath.Equals(PortablePersonalPath, StringComparison.InvariantCultureIgnoreCase))
{
CustomPersonalPath = Path.GetFullPath(customPersonalPath);
if (CustomPersonalPath.Equals(PortablePersonalPath, StringComparison.InvariantCultureIgnoreCase))
{
IsPortable = true;
}
IsPortable = true;
}
if (!string.IsNullOrEmpty(PersonalPath) && !Directory.Exists(PersonalPath))
{
Directory.CreateDirectory(PersonalPath);
}
DebugHelper.WriteLine("CustomPersonalPath changed to: " + CustomPersonalPath);
}
}