Skip to content

Commit

Permalink
- Improved GUI layout, fixed folder rollup
Browse files Browse the repository at this point in the history
- Improved/fixed USB eject
- Improved progress bars, improve
- Bug in calling the upgrade function
  • Loading branch information
D-Jeffrey committed Jan 17, 2025
1 parent 143adf1 commit 4b44f62
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
71 changes: 60 additions & 11 deletions EmbroideryCollection-Cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1064,22 +1064,77 @@ function doWinForm() {
BuildTypeLists
return $SetExiting
}
function EjectUSBandFailed {

Add-Type @"
using System;
using System.Runtime.InteropServices;
public class myFlushFileBuffers
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool FlushFileBuffers(IntPtr hFile);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);
public const uint GENERIC_WRITE = 0x40000000;
public const uint OPEN_EXISTING = 3;
public const uint FILE_FLAG_NO_BUFFERING = 0x20000000;
public static bool FlushDrive(string driveLetter)
{
string path = $"\\\\.\\{driveLetter}:";
IntPtr handle = CreateFile(path, GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, IntPtr.Zero);
if (handle == IntPtr.Zero)
{
throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
}
bool result = FlushFileBuffers(handle);
CloseHandle(handle);
return result;
}
}
"@

function EjectUSB {

# Eject the USB drive
$drv = $USBDrive.Substring(0,1)
for ($wait=0; $wait -lt 20; $wait++) {
try {
if ([MyFlushFileBuffers]::FlushDrive($drv)) {
break
}
} catch {
Write-Error "Error: $_"
break
}
start-sleep -Milliseconds 250
}
$ejectResult = (New-Object -ComObject Shell.Application).Namespace(17).ParseName($usbDrive).InvokeVerb("Eject")
# Check if the USB drive has been ejected successfully
if ($null -eq $ejectResult) {
# Verify that all files are flushed
$fileSystem = Get-WmiObject -Query "SELECT * FROM Win32_LogicalDisk WHERE DeviceID='$usbDrive'"
if ($null -eq $fileSystem.FreeSpace) {
Write-host " ** Ejected ** All files have been written and the USB drive is ready to be safely removed." -ForegroundColor Green
return $false
}
} else {
Write-host "Failed to eject USB drive $usbDrive." -ForegroundColor Red
}
return $true
}
function Test-ExistsOnPath {
param (
Expand Down Expand Up @@ -3224,7 +3279,7 @@ if ($null -eq $LastCheckedGithub -or ($(get-date) -gt $(get-date $LastCheckedGit
if ($upgrademe) {
$upgradescript = Join-Path -Path $PSScriptRoot -ChildPath "install.ps1"
if (test-path $upgradescript) {
powershell -ExecutionPolicy bypass -file $upgradescript -"$ECCVERSION"
powershell -ExecutionPolicy bypass -file $upgradescript -OldVersion "$ECCVERSION"
return
} else {
Write-Warning "Automatic upgrade script '$upgradescript' can not be found to run, continuing without upgrade"
Expand Down Expand Up @@ -3728,13 +3783,7 @@ Complete-Progress
if ($UsingUSBDrive -and $USBEject) {
Show-Progress -Activity "Ejecting USB Drive" -PercentComplete 50
# Eject the USB drive
start-sleep 1
if (EjectUSBandFailed) {
start-sleep 2
if (EjectUSBandFailed) {
Write-host "Warning: Some files may not be completely written. Please try ejecting the USB again." -ForegroundColor Red
}
}
EjectUSB
Complete-Progress
}
Write-Host "End" -ForegroundColor Green
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ It will work with 3 different options:

All while keeping a copy of patterns on your computer for reference along with the instructions. It uses the zip files names for the folder names it creates.

# UPGRADE BUG in v0.8.2
- To overcome a bug to run the upgrade script If your upgrade from 0.8.2 fails. You will need to manually do
- Start -> Run (and paste this line)
- `powershell -ExecutionPolicy bypass -file C:\ProgramData\EmbroideryOrganize\install.ps1`

## Make it work
Once you have downloaded your embroidery files, click on the `icon for EmbroideryCollection-Cleanup` <img src="EmbroideryManager.ico" width="24">. This will start the process of scanning your download folder and moving any sewing files to the Embroidery folder on your computer, using the zip file names to create folder names.

Expand Down Expand Up @@ -116,7 +121,10 @@ They also make the Explorer Plug-in which appears as a right click in File Explo

# Releases
### 0.8.3
- Improved progress bars, improved eject, improve GUI layout, fixed folder rollup
- Improved progress bars, Improve GUI layout, Fixed folder rollup, Improved/fixed USB eject
- Bug in calling the upgrade function
- To overcome a bug for calling of install script. If your upgrade from 0.8.2 fails. You will need to manually do
- Start -> Run `powershell -ExecutionPolicy bypass -file C:\ProgramData\EmbroideryOrganize\install.ps1`
### 0.8.2
- Fixed warning on USB, close on click on X, Progress bars, delete empty folders on USB
- Optimized and fixed Clean Collection, fixed move lone directory and lone files. It now works reliablity
Expand Down

0 comments on commit 4b44f62

Please sign in to comment.