Skip to content

Commit

Permalink
add zh-TW support
Browse files Browse the repository at this point in the history
  • Loading branch information
TkYu committed Apr 21, 2017
1 parent a5abe80 commit 77cd5ac
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 26 deletions.
4 changes: 2 additions & 2 deletions TorrentParserShell/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
14 changes: 12 additions & 2 deletions TorrentParserShell/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions TorrentParserShell/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Parser" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Parser.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="magnet_16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\magnet_16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="magnet_32" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\magnet_32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file removed TorrentParserShell/Resources/Parser.png
Binary file not shown.
Binary file added TorrentParserShell/Resources/magnet_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TorrentParserShell/Resources/magnet_32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions TorrentParserShell/RestartExplorer.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@echo off
taskkill /f /im explorer.exe
start explorer.exe
start explorer.exe %~dp0
57 changes: 50 additions & 7 deletions TorrentParserShell/TorrentExtension.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -19,16 +21,23 @@ public class TorrentExtension : SharpContextMenu
private static readonly string InfoText;
private static readonly string LInfoText;
private static readonly string CopyFail;


static TorrentExtension()
{
if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.StartsWith("zh", StringComparison.OrdinalIgnoreCase))


if (CultureInfo.CurrentCulture.IetfLanguageTag == "zh-CN")
{
InfoText = "复制磁力链接";
LInfoText = "复制磁力链接(带Tracker)";
CopyFail = "解析磁力链接失败!";
}
else if (CultureInfo.CurrentCulture.IetfLanguageTag == "zh-TW" || CultureInfo.CurrentCulture.IetfLanguageTag == "zh-HK")
{
InfoText = "複製磁力連結";
LInfoText = "複製磁力連結(帶Tracker)";
CopyFail = "解析磁力連結失敗!";
}
else
{
InfoText = "Copy MagnetURI";
Expand All @@ -45,17 +54,19 @@ protected override bool CanShowMenu()
protected override ContextMenuStrip CreateMenu()
{
var menu = new ContextMenuStrip();
var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
var dpi = (int)graphics.DpiX;
var itemParse = new ToolStripMenuItem
{
Name = "tsmP",
Text = InfoText,
Image = Properties.Resources.Parser
Image = dpi < 192 ? Properties.Resources.magnet_16 : Properties.Resources.magnet_32
};
var itemParseL = new ToolStripMenuItem
{
Name = "tsmPL",
Text = LInfoText,
Image = Properties.Resources.Parser
Image = dpi < 192 ? Properties.Resources.magnet_16 : Properties.Resources.magnet_32
};
itemParse.Click += ItemParse_Click;
itemParseL.Click += ItemParse_Click;
Expand All @@ -82,14 +93,16 @@ private void ItemParse_Click(object sender, EventArgs e)
}
if (count <= 0)
{
MessageBox.Show(CopyFail, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
//MessageBox.Show(CopyFail, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
Helper.ShowBalloon(CopyFail, "Attention", SystemIcons.Error);
return;
}
Clipboard.SetText(textBuilder.ToString().TrimEnd('\n', '\r'));
}
catch (Exception ex)
{
MessageBox.Show($"{CopyFail}:\n{ex.Message}", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
//MessageBox.Show($"{CopyFail}:\n{ex.Message}", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Error);
Helper.ShowBalloon($"{CopyFail}:\n{ex.Message}", "Attention", SystemIcons.Error);
}
}
}
Expand All @@ -106,7 +119,7 @@ public class TorrentInfoTipHandler : SharpInfoTipHandler

static TorrentInfoTipHandler()
{
if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.StartsWith("zh", StringComparison.OrdinalIgnoreCase))
if (CultureInfo.CurrentCulture.IetfLanguageTag == "zh-CN")
{
FolderStr = "文件夹 ";
CannotParse = "无法解析,文件过大。";
Expand All @@ -118,6 +131,19 @@ static TorrentInfoTipHandler()
{2}
创建时间:{3}";
}
else if (CultureInfo.CurrentCulture.IetfLanguageTag == "zh-TW" || CultureInfo.CurrentCulture.IetfLanguageTag == "zh-HK")
{
FolderStr = "資料夾 ";
CannotParse = "無法解析,檔案過大。";
ParseFail = "種子解析失敗!";
Template = @"種子標題: {0}
檔案清單({1}個檔案):
{2}
建立日期: {3}";
}
else
{
Expand Down Expand Up @@ -171,4 +197,21 @@ protected override string GetInfo(RequestedInfoType infoType, bool singleLine)
}
}
}

public static class Helper
{
public static void ShowBalloon(string body, string title = null, Icon icon = null,int timeout = 3)
{
using (var notification = new NotifyIcon
{
Visible = true,
Icon = icon??SystemIcons.Information,
BalloonTipTitle = title?? "TorrentParser",
BalloonTipText = body
})
{
notification.ShowBalloonTip(timeout);
}
}
}
}
15 changes: 6 additions & 9 deletions TorrentParserShell/TorrentParserShell.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,26 @@
<Compile Include="TorrentExtension.cs" />
</ItemGroup>
<ItemGroup>
<None Include="install.cmd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Key.snk" />
<None Include="packages.config" />
<None Include="uninstall.cmd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Parser.png" />
</ItemGroup>
<ItemGroup>
<None Include="srm.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Resources\magnet_32.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\magnet_16.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
5 changes: 1 addition & 4 deletions TorrentParserShell/uninstall.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@echo off
cd /d %~dp0
rem srm uninstall TorrentParserShell.dll
taskkill /f /im explorer.exe
start explorer.exe
start explorer.exe %~dp0
srm uninstall TorrentParserShell.dll
30 changes: 30 additions & 0 deletions TorrentParserShell/uninstall_test.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off
cd /d %~dp0
rem srm uninstall TorrentParserShell.dll
FOR /F "tokens=3 delims= " %%G in ('reg query "hklm\system\controlset001\control\nls\language" /v Installlanguage') DO (
IF [%%G] EQU [0409] (
goto enUS
)
IF [%%G] EQU [0404] (
goto zhTW
)
goto zhCN
)

:zhCN
echo 按任意键重启explorer以使其生效,如不需要请直接关闭
goto restart

:zhTW
echo 按任意鍵重啟explorer以使其生效,如不需要請直接關閉
goto restart

:enUS
echo Press any key to restart explorer.
goto restart

:restart
pause>nul
taskkill /f /im explorer.exe
start explorer.exe
start explorer.exe %~dp0

0 comments on commit 77cd5ac

Please sign in to comment.