mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
try to load the latest help file in preferred language from getgreenshot.org, using local help files as fallback
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1764 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
afc9c37ce5
commit
fc0d32a82f
6 changed files with 87 additions and 138 deletions
|
@ -673,7 +673,7 @@ namespace Greenshot {
|
||||||
|
|
||||||
#region help
|
#region help
|
||||||
void HelpToolStripMenuItem1Click(object sender, System.EventArgs e) {
|
void HelpToolStripMenuItem1Click(object sender, System.EventArgs e) {
|
||||||
new HelpBrowserForm(coreConf.Language).Show();
|
HelpFileLoader.LoadHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AboutToolStripMenuItemClick(object sender, System.EventArgs e) {
|
void AboutToolStripMenuItemClick(object sender, System.EventArgs e) {
|
||||||
|
|
|
@ -874,17 +874,7 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Contextmenu_helpClick(object sender, EventArgs e) {
|
void Contextmenu_helpClick(object sender, EventArgs e) {
|
||||||
if (helpBrowserForm != null) {
|
HelpFileLoader.LoadHelp();
|
||||||
WindowDetails.ToForeground(helpBrowserForm.Handle);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
using (helpBrowserForm = new HelpBrowserForm(conf.Language)) {
|
|
||||||
helpBrowserForm.ShowDialog();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
helpBrowserForm = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Contextmenu_exitClick(object sender, EventArgs e) {
|
void Contextmenu_exitClick(object sender, EventArgs e) {
|
||||||
|
|
|
@ -169,6 +169,7 @@
|
||||||
<Compile Include="Helpers\IECaptureHelper.cs" />
|
<Compile Include="Helpers\IECaptureHelper.cs" />
|
||||||
<Compile Include="Helpers\IEInterop\IEContainer.cs" />
|
<Compile Include="Helpers\IEInterop\IEContainer.cs" />
|
||||||
<Compile Include="Helpers\ProcessorHelper.cs" />
|
<Compile Include="Helpers\ProcessorHelper.cs" />
|
||||||
|
<Compile Include="Help\HelpFileLoader.cs" />
|
||||||
<Compile Include="Processors\TitleFixProcessor.cs" />
|
<Compile Include="Processors\TitleFixProcessor.cs" />
|
||||||
<None Include="Greenshot.exe.config">
|
<None Include="Greenshot.exe.config">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
|
76
Greenshot/Help/HelpBrowserForm.Designer.cs
generated
76
Greenshot/Help/HelpBrowserForm.Designer.cs
generated
|
@ -1,76 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
|
||||||
*
|
|
||||||
* For more information see: http://getgreenshot.org/
|
|
||||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 1 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
namespace Greenshot.Help
|
|
||||||
{
|
|
||||||
partial class HelpBrowserForm : System.Windows.Forms.Form
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Designer variable used to keep track of non-visual components.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes resources used by the form.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing) {
|
|
||||||
if (components != null) {
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This method is required for Windows Forms designer support.
|
|
||||||
/// Do not change the method contents inside the source code editor. The Forms designer might
|
|
||||||
/// not be able to load this method if it was changed manually.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm));
|
|
||||||
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
|
|
||||||
this.SuspendLayout();
|
|
||||||
//
|
|
||||||
// webBrowser1
|
|
||||||
//
|
|
||||||
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
this.webBrowser1.Location = new System.Drawing.Point(0, 0);
|
|
||||||
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
|
|
||||||
this.webBrowser1.Name = "webBrowser1";
|
|
||||||
this.webBrowser1.Size = new System.Drawing.Size(412, 560);
|
|
||||||
this.webBrowser1.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// HelpBrowserForm
|
|
||||||
//
|
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
|
||||||
this.ClientSize = new System.Drawing.Size(412, 560);
|
|
||||||
this.Controls.Add(this.webBrowser1);
|
|
||||||
this.Name = "HelpBrowserForm";
|
|
||||||
this.Text = "Greenshot Help";
|
|
||||||
this.ResumeLayout(false);
|
|
||||||
}
|
|
||||||
private System.Windows.Forms.WebBrowser webBrowser1;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
|
||||||
*
|
|
||||||
* For more information see: http://getgreenshot.org/
|
|
||||||
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 1 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Greenshot.Configuration;
|
|
||||||
using GreenshotPlugin.Core;
|
|
||||||
|
|
||||||
namespace Greenshot.Help {
|
|
||||||
/// <summary>
|
|
||||||
/// Description of HelpBrowserForm.
|
|
||||||
/// </summary>
|
|
||||||
public partial class HelpBrowserForm {
|
|
||||||
private ILanguage lang;
|
|
||||||
public HelpBrowserForm(string language) {
|
|
||||||
//
|
|
||||||
// The InitializeComponent() call is required for Windows Forms designer support.
|
|
||||||
//
|
|
||||||
InitializeComponent();
|
|
||||||
this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();
|
|
||||||
lang = Language.GetInstance();
|
|
||||||
|
|
||||||
webBrowser1.Url = new Uri(Path.Combine("path://", lang.GetHelpFilePath()));
|
|
||||||
|
|
||||||
updateUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateUI() {
|
|
||||||
|
|
||||||
this.Text = lang.GetString(LangKey.help_title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
84
Greenshot/Help/HelpFileLoader.cs
Normal file
84
Greenshot/Help/HelpFileLoader.cs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Created by SharpDevelop.
|
||||||
|
* User: jens
|
||||||
|
* Date: 09.04.2012
|
||||||
|
* Time: 19:24
|
||||||
|
*
|
||||||
|
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||||
|
*/
|
||||||
|
using Greenshot.Configuration;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Net;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Greenshot.Help
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Description of HelpFileLoader.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class HelpFileLoader
|
||||||
|
{
|
||||||
|
|
||||||
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(HelpFileLoader));
|
||||||
|
|
||||||
|
private const string EXT_HELP_URL = @"http://getgreenshot.org/help/";
|
||||||
|
|
||||||
|
private HelpFileLoader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LoadHelp() {
|
||||||
|
string uri = findOnlineHelpUrl(Language.GetInstance().CurrentLanguage);
|
||||||
|
if(uri == null) {
|
||||||
|
uri = Language.GetInstance().GetHelpFilePath();
|
||||||
|
}
|
||||||
|
Process.Start(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <returns>URL of help file in selected ietf, or (if not present) default ietf, or null (if not present, too. probably indicating that there is no internet connection)</returns>
|
||||||
|
private static string findOnlineHelpUrl(string currentIETF) {
|
||||||
|
string ret = null;
|
||||||
|
|
||||||
|
string extHelpUrlForCurrrentIETF = EXT_HELP_URL;
|
||||||
|
|
||||||
|
if(!currentIETF.Equals("en_US")) {
|
||||||
|
extHelpUrlForCurrrentIETF += currentIETF.ToLower() + "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpStatusCode? s = getHttpStatus(extHelpUrlForCurrrentIETF);
|
||||||
|
if(s == HttpStatusCode.OK) {
|
||||||
|
ret = extHelpUrlForCurrrentIETF;
|
||||||
|
} else if(s != null && !extHelpUrlForCurrrentIETF.Equals(EXT_HELP_URL)) {
|
||||||
|
LOG.Debug(String.Format("Localized online help not found at %s, will try %s as fallback", extHelpUrlForCurrrentIETF, EXT_HELP_URL));
|
||||||
|
s = getHttpStatus(EXT_HELP_URL);
|
||||||
|
if(s == HttpStatusCode.OK) {
|
||||||
|
ret = EXT_HELP_URL;
|
||||||
|
} else {
|
||||||
|
LOG.Warn(String.Format("%s returned status %s", EXT_HELP_URL, s));
|
||||||
|
}
|
||||||
|
} else if(s == null){
|
||||||
|
LOG.Info("Internet connection does not seem to be available, will load help from file system.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves HTTP status for a given url.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="url">URL for which the HTTP status is to be checked</param>
|
||||||
|
/// <returns>An HTTP status code, or null if there is none (probably indicating that there is no internet connection available</returns>
|
||||||
|
private static HttpStatusCode? getHttpStatus(string url) {
|
||||||
|
try {
|
||||||
|
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
|
||||||
|
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
|
||||||
|
return res.StatusCode;
|
||||||
|
} catch(WebException e) {
|
||||||
|
if(e.Response != null) return ((HttpWebResponse)e.Response).StatusCode;
|
||||||
|
else return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue