Small stability fixes

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1811 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-21 14:12:03 +00:00
parent 9017331dc5
commit 9b7c7a9b7e
4 changed files with 86 additions and 55 deletions

View file

@ -57,6 +57,7 @@ namespace Greenshot.Forms
this.checkboxDateTime = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxDateTime = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.button_cancel = new GreenshotPlugin.Controls.GreenshotButton(); this.button_cancel = new GreenshotPlugin.Controls.GreenshotButton();
this.checkboxPrintInverted = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.checkboxPrintInverted = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.checkbox_grayscale = new GreenshotPlugin.Controls.GreenshotCheckBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// checkbox_dontaskagain // checkbox_dontaskagain
@ -65,7 +66,7 @@ namespace Greenshot.Forms
this.checkbox_dontaskagain.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkbox_dontaskagain.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_dontaskagain.LanguageKey = "printoptions_dontaskagain"; this.checkbox_dontaskagain.LanguageKey = "printoptions_dontaskagain";
this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 152); this.checkbox_dontaskagain.Location = new System.Drawing.Point(12, 158);
this.checkbox_dontaskagain.Name = "checkbox_dontaskagain"; this.checkbox_dontaskagain.Name = "checkbox_dontaskagain";
this.checkbox_dontaskagain.Size = new System.Drawing.Size(240, 17); this.checkbox_dontaskagain.Size = new System.Drawing.Size(240, 17);
this.checkbox_dontaskagain.TabIndex = 19; this.checkbox_dontaskagain.TabIndex = 19;
@ -135,8 +136,9 @@ namespace Greenshot.Forms
// //
// button_ok // button_ok
// //
this.button_ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK; this.button_ok.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button_ok.Location = new System.Drawing.Point(187, 179); this.button_ok.Location = new System.Drawing.Point(187, 207);
this.button_ok.Name = "button_ok"; this.button_ok.Name = "button_ok";
this.button_ok.Size = new System.Drawing.Size(75, 23); this.button_ok.Size = new System.Drawing.Size(75, 23);
this.button_ok.TabIndex = 25; this.button_ok.TabIndex = 25;
@ -162,7 +164,7 @@ namespace Greenshot.Forms
// button_cancel // button_cancel
// //
this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.button_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button_cancel.Location = new System.Drawing.Point(268, 179); this.button_cancel.Location = new System.Drawing.Point(268, 207);
this.button_cancel.Name = "button_cancel"; this.button_cancel.Name = "button_cancel";
this.button_cancel.Size = new System.Drawing.Size(75, 23); this.button_cancel.Size = new System.Drawing.Size(75, 23);
this.button_cancel.TabIndex = 27; this.button_cancel.TabIndex = 27;
@ -175,20 +177,34 @@ namespace Greenshot.Forms
this.checkboxPrintInverted.CheckAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxPrintInverted.ImageAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxPrintInverted.LanguageKey = "printoptions_inverted"; this.checkboxPrintInverted.LanguageKey = "printoptions_inverted";
this.checkboxPrintInverted.Location = new System.Drawing.Point(12, 132); this.checkboxPrintInverted.Location = new System.Drawing.Point(12, 135);
this.checkboxPrintInverted.Name = "checkboxPrintInverted"; this.checkboxPrintInverted.Name = "checkboxPrintInverted";
this.checkboxPrintInverted.PropertyName = "OutputPrintInverted"; this.checkboxPrintInverted.PropertyName = "OutputPrintInverted";
this.checkboxPrintInverted.Size = new System.Drawing.Size(141, 17); this.checkboxPrintInverted.Size = new System.Drawing.Size(141, 17);
this.checkboxPrintInverted.TabIndex = 28; this.checkboxPrintInverted.TabIndex = 28;
this.checkboxPrintInverted.Text = "Print with inverted colors";
this.checkboxPrintInverted.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.checkboxPrintInverted.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkboxPrintInverted.UseVisualStyleBackColor = true; this.checkboxPrintInverted.UseVisualStyleBackColor = true;
// //
// checkbox_grayscale
//
this.checkbox_grayscale.AutoSize = true;
this.checkbox_grayscale.CheckAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_grayscale.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_grayscale.LanguageKey = "printoption_printgrayscale";
this.checkbox_grayscale.Location = new System.Drawing.Point(12, 181);
this.checkbox_grayscale.Name = "checkbox_grayscale";
this.checkbox_grayscale.PropertyName = "OutputPrintGrayscale";
this.checkbox_grayscale.Size = new System.Drawing.Size(56, 17);
this.checkbox_grayscale.TabIndex = 29;
this.checkbox_grayscale.TextAlign = System.Drawing.ContentAlignment.TopLeft;
this.checkbox_grayscale.UseVisualStyleBackColor = true;
//
// PrintOptionsDialog // PrintOptionsDialog
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(355, 212); this.ClientSize = new System.Drawing.Size(355, 242);
this.Controls.Add(this.checkbox_grayscale);
this.Controls.Add(this.checkboxPrintInverted); this.Controls.Add(this.checkboxPrintInverted);
this.Controls.Add(this.button_cancel); this.Controls.Add(this.button_cancel);
this.Controls.Add(this.checkboxDateTime); this.Controls.Add(this.checkboxDateTime);
@ -203,11 +219,11 @@ namespace Greenshot.Forms
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "PrintOptionsDialog"; this.Name = "PrintOptionsDialog";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Greenshot print options"; this.Text = "string ###printoptions_title### not found";
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
} }
private GreenshotPlugin.Controls.GreenshotCheckBox checkbox_grayscale;
private GreenshotPlugin.Controls.GreenshotCheckBox checkboxPrintInverted; private GreenshotPlugin.Controls.GreenshotCheckBox checkboxPrintInverted;
private GreenshotPlugin.Controls.GreenshotButton button_cancel; private GreenshotPlugin.Controls.GreenshotButton button_cancel;
private GreenshotPlugin.Controls.GreenshotCheckBox checkboxDateTime; private GreenshotPlugin.Controls.GreenshotCheckBox checkboxDateTime;

View file

@ -33,14 +33,15 @@ namespace GreenshotPlugin.Controls {
ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService; ITypeResolutionService typeResService = GetService(typeof(ITypeResolutionService)) as ITypeResolutionService;
Assembly currentAssembly = this.GetType().Assembly; Assembly currentAssembly = this.GetType().Assembly;
string assemblyPath = typeResService.GetPathOfAssembly(currentAssembly.GetName()); string assemblyPath = typeResService.GetPathOfAssembly(currentAssembly.GetName());
if (!Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\Greenshot\Languages\"))) { string assemblyDirectory = Path.GetDirectoryName(assemblyPath);
Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\..\Greenshot\Languages\")); if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Greenshot\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Greenshot\Languages\"));
} }
if (!Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\Languages\"))) { if (!Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\Languages\"))) {
Language.AddLanguageFilePath(Path.Combine(Path.GetDirectoryName(assemblyPath), @"..\..\..\Languages\")); Language.AddLanguageFilePath(Path.Combine(assemblyDirectory, @"..\..\..\Languages\"));
} }
} catch (Exception ex) { } catch (Exception ex) {
MessageBox.Show(ex.ToString()); MessageBox.Show(ex.ToString(), "Greenshot designer exception!");
} }
} }
} }

View file

@ -6,6 +6,7 @@ using System.IO;
namespace GreenshotPlugin.Core { namespace GreenshotPlugin.Core {
public static class EncryptionHelper { public static class EncryptionHelper {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger("EncryptionHelper");
private const string RGBIV = "dlgjowejgogkklwj"; private const string RGBIV = "dlgjowejgogkklwj";
private const string KEY = "lsjvkwhvwujkagfauguwcsjgu2wueuff"; private const string KEY = "lsjvkwhvwujkagfauguwcsjgu2wueuff";
@ -15,19 +16,23 @@ namespace GreenshotPlugin.Core {
/// <param name="ClearText">the string to call upon</param> /// <param name="ClearText">the string to call upon</param>
/// <returns>an encryped string in base64 form</returns> /// <returns>an encryped string in base64 form</returns>
public static string Encrypt(this string ClearText) { public static string Encrypt(this string ClearText) {
byte[] clearTextBytes = Encoding.ASCII.GetBytes(ClearText);
string returnValue = null; string returnValue = null;
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); try {
byte[] clearTextBytes = Encoding.ASCII.GetBytes(ClearText);
using (MemoryStream ms = new MemoryStream()) { SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV);
byte[] key = Encoding.ASCII.GetBytes(KEY); using (MemoryStream ms = new MemoryStream()) {
CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write); byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV);
byte[] key = Encoding.ASCII.GetBytes(KEY);
cs.Write(clearTextBytes, 0, clearTextBytes.Length); CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV), CryptoStreamMode.Write);
cs.Close(); cs.Write(clearTextBytes, 0, clearTextBytes.Length);
returnValue = Convert.ToBase64String(ms.ToArray());
cs.Close();
returnValue = Convert.ToBase64String(ms.ToArray());
}
} catch (Exception ex) {
LOG.ErrorFormat("Error encrypting, error: ", ex.Message);
} }
return returnValue; return returnValue;
} }
@ -38,22 +43,26 @@ namespace GreenshotPlugin.Core {
/// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param> /// <param name="EncryptedText">a base64 encoded rijndael encrypted string</param>
/// <returns>Decrypeted text</returns> /// <returns>Decrypeted text</returns>
public static string Decrypt(this string EncryptedText) { public static string Decrypt(this string EncryptedText) {
byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
string returnValue = null; string returnValue = null;
using (MemoryStream ms = new MemoryStream()) { try {
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);
using (MemoryStream ms = new MemoryStream()) {
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV);
byte[] key = Encoding.ASCII.GetBytes(KEY);
byte[] rgbIV = Encoding.ASCII.GetBytes(RGBIV);
CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV), byte[] key = Encoding.ASCII.GetBytes(KEY);
CryptoStreamMode.Write);
CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV),
cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length); CryptoStreamMode.Write);
cs.Close(); cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);
returnValue = Encoding.ASCII.GetString(ms.ToArray());
cs.Close();
returnValue = Encoding.ASCII.GetString(ms.ToArray());
}
} catch (Exception ex) {
LOG.ErrorFormat("Error decrypting {0}, error: ", EncryptedText, ex.Message);
} }
return returnValue; return returnValue;

View file

@ -54,25 +54,30 @@ namespace GreenshotPlugin.Core {
/// Static initializer for the language code /// Static initializer for the language code
/// </summary> /// </summary>
static Language() { static Language() {
if (!LogHelper.isInitialized) {
LOG.Warn("Log4net hasn't been initialized yet! (Design mode?)");
LogHelper.InitializeLog4NET();
}
if (!IniConfig.IsInited) { if (!IniConfig.IsInited) {
LOG.Warn("IniConfig hasn't been initialized yet! (Design mode?)"); LOG.Warn("IniConfig hasn't been initialized yet! (Design mode?)");
IniConfig.Init("greenshot", "greenshot"); IniConfig.Init("greenshot", "greenshot");
} }
string applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); if (!LogHelper.isInitialized) {
string applicationFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); LOG.Warn("Log4net hasn't been initialized yet! (Design mode?)");
LogHelper.InitializeLog4NET();
// PAF Path }
AddPath(Path.Combine(applicationFolder, @"App\Greenshot\Languages"));
try {
// Application data path string applicationDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
AddPath(Path.Combine(applicationDataFolder, @"Greenshot\Languages\")); string applicationFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// Startup path // PAF Path
AddPath(Path.Combine(applicationFolder, @"Languages")); AddPath(Path.Combine(applicationFolder, @"App\Greenshot\Languages"));
// Application data path
AddPath(Path.Combine(applicationDataFolder, @"Greenshot\Languages\"));
// Startup path
AddPath(Path.Combine(applicationFolder, @"Languages"));
} catch (Exception pathException) {
LOG.Error(pathException);
}
try { try {
using (RegistryKey languageGroupsKey = Registry.LocalMachine.OpenSubKey(LANGUAGE_GROUPS_KEY, false)) { using (RegistryKey languageGroupsKey = Registry.LocalMachine.OpenSubKey(LANGUAGE_GROUPS_KEY, false)) {