This repository has been archived by the owner on Nov 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: internal refactors #11
Open
iterma
wants to merge
7
commits into
kxxt:master
Choose a base branch
from
iterma:classWslDistro
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b96b226
Nullable enabled.
iterma a5487d0
ConvertBack implemented.
iterma cb61eab
Default Exception and ISerializable constructors.
iterma ee4b63e
Exclude class if .NET5 or greater.
iterma 01c1ba7
feat: more icons
iterma be17854
New constructor.
iterma a44d046
Merge branch 'master' into classWslDistro
iterma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,13 @@ namespace WSLDiskShrinker.Common; | |
|
||
class BooleanToVisibilityConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
bool v = (bool)value; | ||
return v ? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return (bool)value ? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return (bool)value ? Visibility.Collapsed : Visibility.Visible; // Not used. | ||
} | ||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same issue here. Wrong implementation here. And definitely no need to implement it. |
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
namespace WSLDiskShrinker.Common; | ||
using System.Runtime.Serialization; | ||
|
||
public class CommandFailedException : Exception | ||
namespace WSLDiskShrinker.Common; | ||
|
||
[Serializable] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point of making it |
||
public class CommandFailedException : Exception /* ISerializable */ | ||
{ | ||
public Process FailedProcess { get; set; } | ||
public CommandFailedException(Process p) | ||
{ | ||
this.FailedProcess = p; | ||
} | ||
} | ||
public Process? FailedProcess { get; } | ||
public CommandFailedException(Process p) | ||
{ | ||
this.FailedProcess = p; | ||
} | ||
|
||
// Implement exception constructors (not used). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding implementations that are not used 😂? |
||
public CommandFailedException() : base() { } | ||
public CommandFailedException(string? message) : base(message) { } | ||
public CommandFailedException(string? message, Exception? innerException) : base(message, innerException) { } | ||
|
||
// ISerializable should be implemented (not used). | ||
protected CommandFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
using System.Threading; | ||
#if !NET5_0_OR_GREATER | ||
|
||
using System.Threading; | ||
|
||
namespace WSLDiskShrinker.Common; | ||
|
||
// https://stackoverflow.com/questions/470256/process-waitforexit-asynchronously | ||
static class ProcessExtension | ||
{ | ||
/// <summary> | ||
/// Waits asynchronously for the process to exit. | ||
/// </summary> | ||
/// <param name="process">The process to wait for cancellation.</param> | ||
/// <param name="cancellationToken">A cancellation token. If invoked, the task will return | ||
/// immediately as canceled.</param> | ||
/// <returns>A Task representing waiting for the process to end.</returns> | ||
public static Task CustomWaitForExitAsync(this Process process, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
if (process.HasExited) return Task.CompletedTask; | ||
/// <summary>Waits asynchronously for the process to exit.</summary> | ||
/// <param name="process">The process to wait for cancellation.</param> | ||
/// <param name="cancellationToken">A cancellation token. If invoked, the task will return immediately as canceled.</param> | ||
/// <returns>A Task representing waiting for the process to end.</returns> | ||
public static Task CustomWaitForExitAsync(this Process process, CancellationToken cancellationToken = default) | ||
{ | ||
if (process.HasExited) return Task.CompletedTask; | ||
|
||
var tcs = new TaskCompletionSource<object>(); | ||
process.EnableRaisingEvents = true; | ||
process.Exited += (sender, args) => tcs.TrySetResult(null); | ||
if (cancellationToken != default) | ||
cancellationToken.Register(() => tcs.SetCanceled()); | ||
var tcs = new TaskCompletionSource<object>(); | ||
process.EnableRaisingEvents = true; | ||
process.Exited += (sender, args) => tcs.TrySetResult(process.ExitCode); | ||
if (cancellationToken != default) cancellationToken.Register(() => tcs.SetCanceled()); | ||
|
||
return process.HasExited ? Task.CompletedTask : tcs.Task; | ||
} | ||
return process.HasExited ? Task.CompletedTask : tcs.Task; | ||
} | ||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation of
ConvertBack
is not correct. WhatConvertBack
should do is converting fromVisibility
tobool
, which is useless for our case. (FYI: It is useful in two-way bindings)