Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 76 additions & 36 deletions FreeMove/Form1.Designer.cs

Large diffs are not rendered by default.

126 changes: 109 additions & 17 deletions FreeMove/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public Form1()

private async void Form1_Load(object sender, EventArgs e)
{
ApplyLanguage();
SetToolTips();




//Check whether the program is set to update on its start
if (Settings.AutoUpdate)
{
Expand Down Expand Up @@ -77,21 +81,72 @@ private async void Form1_Load(object sender, EventArgs e)

#endregion

/// <summary>
/// 根据当前 UI 语言刷新界面上的文本(按钮/菜单/标签等)
/// </summary>
private void ApplyLanguage()
{
// 窗口标题
Text = Properties.Resources.ResourceManager.GetString("Form_Title");

// 标签和按钮
label1.Text = Properties.Resources.ResourceManager.GetString("Label_From");
label2.Text = Properties.Resources.ResourceManager.GetString("Label_To");
button_BrowseFrom.Text = Properties.Resources.ResourceManager.GetString("Button_Browse");
button_BrowseTo.Text = Properties.Resources.ResourceManager.GetString("Button_Browse");
button_Move.Text = Properties.Resources.ResourceManager.GetString("Button_Move");
button_Close.Text = Properties.Resources.ResourceManager.GetString("Button_Close");
chkBox_originalHidden.Text = Properties.Resources.ResourceManager.GetString("Checkbox_OriginalHidden");
chkBox_createDest.Text = Properties.Resources.ResourceManager.GetString("Checkbox_CreateDest");

// 菜单
settingsToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Settings");
infoToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Info");
lunguToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Language");

checkForUpdateToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_CheckForUpdate");
checkNowToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_CheckNow");
checkOnProgramStartToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_CheckOnStart");

PermissionCheckToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_PermissionCheck");
safeModeToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_SafeMode");

noneToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_None");
fastToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Fast");
fullToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Full");

reportAnIssueToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_ReportIssue");
gitHubToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_GitHub");
aboutToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_About");
helpToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("HelpButtonText");

zhToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Lang_English");
chineseToolStripMenuItem.Text = Properties.Resources.ResourceManager.GetString("Menu_Lang_Chinese");

// 语言菜单打勾状态
string lang = Settings.Language;
// lang 为空时:跟随系统,这里根据当前 Culture 判定
string current = System.Globalization.CultureInfo.CurrentUICulture.Name;
bool isChinese = (!string.IsNullOrEmpty(lang) ? lang : current).StartsWith("zh", StringComparison.OrdinalIgnoreCase);
zhToolStripMenuItem.Checked = !isChinese;
chineseToolStripMenuItem.Checked = isChinese;
}

private bool PreliminaryCheck(string source, string destination)
{
//Check for errors before copying
try
{
IOHelper.CheckDirectories(source, destination, safeMode);
}
catch(AggregateException ae)
catch (AggregateException ae)
{
var msg = "";
foreach (var ex in ae.InnerExceptions)
{
msg += ex.Message + "\n";
}
MessageBox.Show(msg, "Error");
MessageBox.Show(msg, Properties.Resources.ResourceManager.GetString("ErrorTitle"));
return false;
}
return true;
Expand All @@ -117,11 +172,12 @@ private async void Begin()
olddir.Attributes = attrib | FileAttributes.Hidden;
}

MessageBox.Show(this, "Done!");
MessageBox.Show(this, Properties.Resources.ResourceManager.GetString("DoneMessage"));
}
catch (IO.MoveOperation.CopyFailedException ex)
{
switch (MessageBox.Show(this, string.Format($"Do you want to undo the changes?\n\nDetails:\n{ex.InnerException.Message}"), ex.Message, MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
string question = string.Format(Properties.Resources.ResourceManager.GetString("UndoChangesDetailsQuestion"), ex.InnerException.Message);
switch (MessageBox.Show(this, question, ex.Message, MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
try
Expand All @@ -130,7 +186,7 @@ private async void Begin()
}
catch (Exception ie)
{
MessageBox.Show(this, ie.Message, "Could not remove copied contents. Try removing manually");
MessageBox.Show(this, ie.Message, Properties.Resources.ResourceManager.GetString("RemoveCopiedContentsFailed"));
}
break;
case DialogResult.No:
Expand All @@ -140,7 +196,8 @@ private async void Begin()
}
catch (IO.MoveOperation.DeleteFailedException ex)
{
switch (MessageBox.Show(this, string.Format($"Do you want to undo the changes?\n\nDetails:\n{ex.InnerException.Message}"), ex.Message, MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
string question = string.Format(Properties.Resources.ResourceManager.GetString("UndoChangesDetailsQuestion"), ex.InnerException.Message);
switch (MessageBox.Show(this, question, ex.Message, MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
try
Expand All @@ -149,7 +206,7 @@ private async void Begin()
}
catch (Exception ie)
{
MessageBox.Show(this, ie.Message, "Could not move back contents. Try moving manually");
MessageBox.Show(this, ie.Message, Properties.Resources.ResourceManager.GetString("MoveBackFailedMessage"));
}
break;
case DialogResult.No:
Expand All @@ -159,11 +216,14 @@ private async void Begin()
}
catch (IO.MoveOperation.MoveFailedException ex)
{
MessageBox.Show(this, string.Format($"Details:\n{ex.InnerException.Message}"), ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
string details = string.Format(Properties.Resources.ResourceManager.GetString("MoveFailedDetailsFormat"), ex.InnerException.Message);
MessageBox.Show(this, details, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (OperationCanceledException)
{
switch (MessageBox.Show(this, string.Format($"Do you want to undo the changes?"), "Cancelled", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
string question = Properties.Resources.ResourceManager.GetString("UndoChangesSimpleQuestion");
string title = Properties.Resources.ResourceManager.GetString("CancelledTitle");
switch (MessageBox.Show(this, question, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
try
Expand All @@ -185,7 +245,7 @@ private async void Begin()
private async Task BeginMove(string source, string destination)
{
//Move files
using (ProgressDialog progressDialog = new ProgressDialog("Moving files..."))
using (ProgressDialog progressDialog = new ProgressDialog(Properties.Resources.ResourceManager.GetString("MovingFilesTitle")))
{
IO.MoveOperation moveOp = IOHelper.MoveDir(source, destination);

Expand All @@ -194,7 +254,9 @@ private async Task BeginMove(string source, string destination)

progressDialog.CancelRequested += (sender, e) =>
{
if (DialogResult.Yes == MessageBox.Show(this, "Are you sure you want to cancel?", "Cancel confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
string message = Properties.Resources.ResourceManager.GetString("CancelConfirmationMessage");
string title = Properties.Resources.ResourceManager.GetString("CancelConfirmationTitle");
if (DialogResult.Yes == MessageBox.Show(this, message, title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
{
moveOp.Cancel();
progressDialog.BeginInvoke(new Action(() => progressDialog.Cancellable = false));
Expand Down Expand Up @@ -230,9 +292,9 @@ private void SetToolTips()
InitialDelay = 600,
ReshowDelay = 500
};
Tip.SetToolTip(this.textBox_From, "Select the folder you want to move");
Tip.SetToolTip(this.textBox_To, "Select where you want to move the folder");
Tip.SetToolTip(this.chkBox_originalHidden, "Select whether you want to hide the shortcut which is created in the old location or not");
Tip.SetToolTip(this.textBox_From, Properties.Resources.ResourceManager.GetString("TooltipFrom"));
Tip.SetToolTip(this.textBox_To, Properties.Resources.ResourceManager.GetString("TooltipTo"));
Tip.SetToolTip(this.chkBox_originalHidden, Properties.Resources.ResourceManager.GetString("TooltipHidden"));
}

private void Reset()
Expand All @@ -244,7 +306,8 @@ private void Reset()

public static void Unauthorized(Exception ex)
{
MessageBox.Show(Properties.Resources.ErrorUnauthorizedMoveDetails + ex.Message, "Error details");
string title = Properties.Resources.ResourceManager.GetString("ErrorDetailsTitle");
MessageBox.Show(Properties.Resources.ErrorUnauthorizedMoveDetails + ex.Message, title);
}

#region Event Handlers
Expand Down Expand Up @@ -327,12 +390,14 @@ private void CheckOnProgramStartToolStripMenuItem_Click(object sender, EventArgs
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
string msg = String.Format(Properties.Resources.AboutContent, System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion);
MessageBox.Show(msg, "About FreeMove");
string title = Properties.Resources.ResourceManager.GetString("AboutTitle");
MessageBox.Show(msg, title);
}

private void SafeModeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show(Properties.Resources.DisableSafeModeMessage, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
string title = Properties.Resources.ResourceManager.GetString("WarningTitle");
if (MessageBox.Show(Properties.Resources.DisableSafeModeMessage, title, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
safeMode = false;
safeModeToolStripMenuItem.Checked = false;
Expand Down Expand Up @@ -363,5 +428,32 @@ private void FullToolStripMenuItem_Click(object sender, EventArgs e)
fastToolStripMenuItem.Checked = false;
fullToolStripMenuItem.Checked = true;
}

private void zhToolStripMenuItem_Click(object sender, EventArgs e)
{
// 切换为英文界面
Settings.Language = "en";
string msg = Properties.Resources.ResourceManager.GetString("LanguageChangedRestartMessage");
string title = Properties.Resources.ResourceManager.GetString("LanguageChangedTitle");
MessageBox.Show(msg, title);
Application.Restart();
}

private void chineseToolStripMenuItem_Click(object sender, EventArgs e)
{
// 切换为简体中文界面
Settings.Language = "zh-Hans";
string msg = Properties.Resources.ResourceManager.GetString("LanguageChangedRestartMessage");
string title = Properties.Resources.ResourceManager.GetString("LanguageChangedTitle");
MessageBox.Show(msg, title);
Application.Restart();
}

private void HelpToolStripMenuItem_Click(object sender, EventArgs e)
{
string help = Properties.Resources.ResourceManager.GetString("HelpContent");
string title = Properties.Resources.ResourceManager.GetString("HelpButtonText");
MessageBox.Show(this, help, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
6 changes: 5 additions & 1 deletion FreeMove/FreeMove.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>9.0</LangVersion>
<OutputType>WinExe</OutputType>
<PublishUrl>publish\</PublishUrl>
<PublishSingleFile>true</PublishSingleFile>
Expand Down Expand Up @@ -39,11 +40,14 @@
<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.4" />
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
</ItemGroup>
</Project>
49 changes: 48 additions & 1 deletion FreeMove/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Security.Principal;

namespace FreeMove
{
Expand All @@ -30,8 +33,52 @@ static class Program
[STAThread]
static void Main()
{
// 如非管理员权限,提示并退出
try
{
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
{
string msg = Properties.Resources.ResourceManager.GetString("AdminRequiredMessage");
string title = Properties.Resources.ResourceManager.GetString("AdminRequiredTitle");
MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
}
catch
{
// 如果检查失败,出于安全考虑也直接退出
string msg = Properties.Resources.ResourceManager.GetString("AdminRequiredMessage");
string title = Properties.Resources.ResourceManager.GetString("AdminRequiredTitle");
MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

// 设置全局语言:优先使用用户在设置中选择的语言,否则跟随系统
try
{
string lang = Settings.Language;
CultureInfo culture;
if (!string.IsNullOrEmpty(lang))
{
culture = new CultureInfo(lang);
}
else
{
culture = CultureInfo.InstalledUICulture;
}
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
}
catch
{
// 如果设置中的语言代码无效,忽略并使用系统默认
}

Application.EnableVisualStyles();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Expand Down
3 changes: 2 additions & 1 deletion FreeMove/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void UpdateProgress(IO.IOOperation.ProgressChangedEventArgs e)
label_Progress?.BeginInvoke(new Action(() =>
{
float percentage = ((float)e.Progress / e.Max);
label_Progress.Text = e.Progress == e.Max ? "Finishing..." : $"{e.Progress}/{e.Max}";
string finishing = Properties.Resources.ResourceManager.GetString("ProgressFinishingText");
label_Progress.Text = e.Progress == e.Max ? finishing : $"{e.Progress}/{e.Max}";
if (e.Progress == e.Max)
Cancellable = false;
// label_Progress.Text = $"{percentage*100f, 3:0.0}%";
Expand Down
Loading