Skip to content

Commit

Permalink
Merge pull request #33 from eltos/win8compat
Browse files Browse the repository at this point in the history
Win8 compatibility
  • Loading branch information
eltos authored Nov 9, 2023
2 parents 2c45a78 + 47cee1b commit f554e47
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 36 deletions.
27 changes: 23 additions & 4 deletions PasteIntoFile/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace PasteIntoFile {
public partial class Dialog : MasterForm {
private ClipboardContents clipData = new ClipboardContents();
private int saveCount = 0;
private bool _formLoaded = false;

private SharpClipboard _clipMonitor;
private bool disableUiEvents = false;
Expand Down Expand Up @@ -128,32 +129,50 @@ public Dialog(string location = null, string filename = null, bool? showDialogOv
Program.ShowBalloon(Resources.str_autosave_balloontitle,
new[] { file, Resources.str_autosave_balloontext }, 10);
Environment.ExitCode = 0;
Close();
CloseAsSoonAsPossible();
};

ExplorerUtil.AsyncRequestFilenameEdit(file);

// Timeout in case filename edit fails
Task.Delay(new TimeSpan(0, 0, 0, 10)).ContinueWith(o => Close());
Task.Delay(new TimeSpan(0, 0, 0, 3)).ContinueWith(o => CloseAsSoonAsPossible());

} else {
// exit immediately
Program.ShowBalloon(Resources.str_autosave_balloontitle,
new[] { file, Resources.str_autosave_balloontext }, 10);
Environment.ExitCode = 0;
Close();
CloseAsSoonAsPossible();
}

} else {
// save failed, exit with error code
Environment.ExitCode = 1;
Close();
CloseAsSoonAsPossible();
}

}

}

protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
_formLoaded = true;
}

/// <summary>
/// Close the form as soon as possible.
/// Unless <code>Close()</code> this method is save to call from within the constructor.
/// See https://stackoverflow.com/questions/3067901
/// </summary>
private void CloseAsSoonAsPossible() {
if (_formLoaded) { // Already loaded, save to call Close
Close();
} else { // Close once loading completed
Load += (sender, args) => Close();
}
}

private void updateUiFromSettings() {
disableUiEvents = true;
chkClrClipboard.Checked = Settings.Default.clrClipboard;
Expand Down
7 changes: 5 additions & 2 deletions PasteIntoFile/ExplorerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Shell32;

namespace PasteIntoFile {
Expand Down Expand Up @@ -72,7 +73,9 @@ private static void SelectFileInWindow(SHDocVw.InternetExplorer window, string p
}

/// <summary>
/// Request file name edit by user in active explorer path
/// Request file name edit by user in active explorer path.
/// This method will return immediately, and the FilenameEditComplete event handler
/// will be called asynchronously on success.
/// </summary>
/// <param name="filePath">Path of file to select/edit</param>
/// <param name="edit">can be set to false to select only (without entering edit mode)</param>
Expand Down Expand Up @@ -101,7 +104,7 @@ public static void AsyncRequestFilenameEdit(string filePath, bool edit = true) {
SHParseDisplayName(filePath, IntPtr.Zero, out file, 0, out _);
try {
SHOpenFolderAndSelectItems(file, 0, null, edit ? 1 : 0);
FilenameEditComplete?.Invoke(null, EventArgs.Empty);
Task.Run(() => FilenameEditComplete?.Invoke(null, EventArgs.Empty)); // call asynchronously
} finally {
ILFree(file);
}
Expand Down
42 changes: 27 additions & 15 deletions PasteIntoFile/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.Web.Http;
using Windows.Web.Http.Headers;
using System.Net.Http;
using System.Net.Http.Headers;
using CommandLine;
using CommandLine.Text;
using Microsoft.Toolkit.Uwp.Notifications;
Expand Down Expand Up @@ -445,21 +445,33 @@ public static void RestartAppElevated(string location) {
/// <param name="link">Optional link to visit when clicking the balloon</param>
/// <param name="silent">If true, make a silent balloon (default)</param>
public static void ShowBalloon(string title, string[] message, ushort expire = 5, string link = null, bool silent = true) {
var builder = new ToastContentBuilder().AddText(title);
foreach (var s in message) {
builder.AddText(s);
}
if (silent)
builder.AddAudio(null, null, true);
try {
var builder = new ToastContentBuilder().AddText(title);
foreach (var s in message) {
builder.AddText(s);
}

if (silent)
builder.AddAudio(null, null, true);

if (link != null)
builder.AddButton(Resources.str_open, ToastActivationType.Protocol, link);

if (link != null)
builder.AddButton(Resources.str_open, ToastActivationType.Protocol, link);
builder.Show(toast => {
if (expire > 0) {
toast.ExpirationTime = DateTime.Now.AddSeconds(expire);
}
});

builder.Show(toast => {
if (expire > 0) {
toast.ExpirationTime = DateTime.Now.AddSeconds(expire);
} catch (SystemException) {
// Microsoft.Toolkit.Uwp requires Windows version 1809 (build 17763) or higher
// if that's not available, print to console instead
Console.WriteLine(title);
foreach (var s in message) {
Console.WriteLine(s);
}
});

}
}


Expand All @@ -477,7 +489,7 @@ public static async Task<bool> CheckForUpdates() {
Settings.Default.Save();
try {
var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.Add(new HttpProductInfoHeaderValue("PasteIntoFile", Application.ProductVersion));
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("PasteIntoFile", Application.ProductVersion));
var data = await client.GetStringAsync(new Uri("https://api.github.com/repos/eltos/PasteIntoFile/releases/latest"));
var match = Regex.Match(data, "\"(https://github.com/eltos/PasteIntoFile/releases/tag/v(\\d+(\\.\\d+)*))\"");
if (match.Success && match.Groups[2].Value != Settings.Default.updateLatestVersion) {
Expand Down
4 changes: 3 additions & 1 deletion PasteIntoFile/PasteIntoFile.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PackageReference Include="SharpClipboard" Version="3.5.2" />
<PackageReference Include="Svg" Version="3.4.3" />
</ItemGroup>
<ItemGroup Condition="'$(Flavor)'=='Portable'" >
<ItemGroup Condition="'$(Flavor)'=='Portable'">
<PackageReference Include="PortableSettingsProvider" Version="0.2.4" />
</ItemGroup>
<ItemGroup>
Expand All @@ -72,6 +72,8 @@
<Reference Include="System.Drawing.Design" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion PasteIntoFile/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
// 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.*")]
#if DEBUG
[assembly: AssemblyVersion("5.1.*")]
#else
[assembly: AssemblyVersion("5.1")]
[assembly: AssemblyFileVersion("5.1")]
#endif
9 changes: 9 additions & 0 deletions PasteIntoFile/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions PasteIntoFile/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,7 @@ Diese Einstellungen werden ab dem nächsten Login aktiv.</value>
<value>Speichert Dateien automatisch im Standarddateiformat ohne den Dialog zu zeigen.
Die Umschalttaste gedrückt halten, um diese Einstellung temporär zu invertieren.</value>
</data>
<data name="str_wizard_notify_on_updates" xml:space="preserve">
<value>Über Updates benachrichtigen</value>
</data>
</root>
3 changes: 3 additions & 0 deletions PasteIntoFile/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,7 @@ These setting will take effect on the next login.</value>
<value>Saves clipboard data to default filetype without prompt.
Hold SHIFT to temporarly invert this setting.</value>
</data>
<data name="str_wizard_notify_on_updates" xml:space="preserve">
<value>Notify about updates</value>
</data>
</root>
29 changes: 29 additions & 0 deletions PasteIntoFile/Wizard.Designer.cs

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

17 changes: 17 additions & 0 deletions PasteIntoFile/Wizard.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using PasteIntoFile.Properties;
Expand Down Expand Up @@ -127,6 +128,22 @@ private void ChkPatching_CheckedChanged(object sender, EventArgs e) {
}
}

private void settingsButton_Click(object sender, EventArgs e) {
// update
settingsMenuUpdateChecks.Checked = Settings.Default.updateChecksEnabled;
// show it
Point ptLowerLeft = new Point(4, settingsButton.Height);
ptLowerLeft = settingsButton.PointToScreen(ptLowerLeft);
settingsMenu.Show(ptLowerLeft);
}

private void menuUpdateChecks_CheckedChanged(object sender, EventArgs e) {
if (Settings.Default.updateChecksEnabled != settingsMenuUpdateChecks.Checked) {
Settings.Default.updateChecksEnabled = settingsMenuUpdateChecks.Checked;
Settings.Default.Save();
}
}

private void finish_Click(object sender, EventArgs e) {
Settings.Default.firstLaunch = false;
Settings.Default.Save();
Expand Down
24 changes: 11 additions & 13 deletions PasteIntoFile/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,18 @@

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with.
<!-- A list of all Windows versions that this application is designed to work with.
Windows will automatically select the most compatible environment.-->

<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->

<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->

<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->

<!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>-->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>
</compatibility>
Expand Down

0 comments on commit f554e47

Please sign in to comment.