Skip to content

Commit

Permalink
v0.6.2
Browse files Browse the repository at this point in the history
- Added Logging and remove extra debug code
- Fixed saving parameters via JSON for difference between PS 5,6 vs 7
- fix issue with nest cloud folders add/removing of files and empty folders
  • Loading branch information
D-Jeffrey committed Mar 12, 2024
1 parent 0ba463c commit 48a0b11
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 85 deletions.
144 changes: 81 additions & 63 deletions EmbroideryCollection-Cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ $TandCs = @('TERMS-OF-USAGE.*', 'planetappliquetermsandconditions.*','READ ME FI
$opencloudpage = "https://www.mysewnet.com/en-us/my-account/#/cloud/"
# List of paramstring to check
$paramstring = [ordered]@{
"DownloadDaysOld" = "Age of files in Download directory";
"SetSize" = "Keep collections of files together if there are at least this many";
"EmbroidDir" = "Embriodary Files directory";
"USBDrive"="USB drive letter (example E: or H:)";
"LastCheckedGithub"=""
"LastCheckedGithub"="";
"DownloadDaysOld" = "Age of files in Download directory";
"SetSize" = "Keep collections of files together if there are at least this many"
}


$parambool = [ordered]@{
'KeepAllTypes'= 'Keep all variations of files types' ;
'KeepEmptyDirectory'= 'When cleaning up keep empty folders';
Expand Down Expand Up @@ -103,7 +102,7 @@ $paramswitch =[ordered]@{
#
#

$ECCVERSION = "v0.6.1"
$ECCVERSION = "v0.6.2"
write-host " ".padright(15) "Embroidery Collection Cleanup version: $ECCVERSION".padright(70) -ForegroundColor White -BackgroundColor Blue


Expand Down Expand Up @@ -154,7 +153,7 @@ if (Test-Path -Path $ConfigFile) {

# Iterate over each parameter
if ($null -eq $SwitchDefault) {
$paralist = ($paramstring.Keys )
$paralist = ($paramstring.Keys)
} else {
$paralist = ($paramstring.Keys + $parambool.Keys)
}
Expand All @@ -168,22 +167,25 @@ if (Test-Path -Path $ConfigFile) {
# write-host "$param = " $SavedParam.$param
}
# toggle a Switch Option
if ($isParamPresent -and ($parambool.keys.Contains($param) -and $null -ne $SavedParam.$param)) {
if ($isParamPresent -and ($parambool.Contains($param))) {
Set-Variable -Name $param -Value (-not $SavedParam.$param)
}
}

foreach ($param in ($paramarray.Keys)) {
if ($null -ne $SavedParam.$param) {
Set-Variable -Name $param -Value $SavedParam.$param
$newvalue = $SavedParam.$param.value
if ($null -eq $newvalue) {
$newvalue = $SavedParam.$param
}
Set-Variable -Name $param -Value $newvalue

}
}
} else {
$FirstRun = $true
}



function SaveAllParams
{
# Save the state of the variables and settings
Expand Down Expand Up @@ -244,6 +246,7 @@ if ($env:COMPUTERNAME -eq "DESKTOP-R3PSDBU_") { # -and $Testing) {
}




#=============================================================================================

Expand Down Expand Up @@ -506,7 +509,7 @@ function CheckAndRemove {
$howDeleted = if ($HardDelete) { 'Deleting ' } else { 'Recycling ' }
$fcs = 0
ForEach ($f in $RemoveFiles) {
# TODO need to remove it from $mysewingfiles
RecycleFile -file $f.FullName -purge $DeleteWithoutRecycle
LogAction -File $f.Name -Action "--Remove-file"
ShowProgress ($howDeleted + "extra files from cache") "$fcs of $fcr - $($f.Name)"
Expand Down Expand Up @@ -980,9 +983,25 @@ function GetCloudDirectoryid($foldername) {

Function DeleteCloudFolder ($id)
{
if ($null -eq $id) {
return
}
$authHeader = authHeaderValues
$myError = $null
$requestUri = 'https://api.mysewnet.com/api/v2/cloud/folders/'+ $id;
$webcollection.folderId
$pool = $webcollection
# BUGS
<#
do {
$pool | Select-Object -ExpandProperty Folders | Where-Object {$id -in ($_.folder.Id)} | ForEach-Object {
$_.folderId = ($id -notin ($_.FolderId))
$pool = $null
break
}
$pool = $pool | Select-Object -ExpandProperty Folders
} while ($pool.folders.count -gt 0)
#>
try {
$result = Invoke-RestMethod -Uri $requestUri -Method "DELETE" -Headers $authHeader
} catch {
Expand All @@ -999,6 +1018,7 @@ Function DeleteCloudFolder ($id)
write-warning ("Error Deleting folder id: '$id' [ " + $eDetails.message + " ] -- The cloud API is buggy try again")
}
else {

# TODO Manage the copy of the shadow structure for Cloud files
}
return $result
Expand Down Expand Up @@ -1510,16 +1530,12 @@ function BuildHashofMySewingFiles {
function ShowPreferences ($showall = $false)
{
if ($showall) {
foreach ($paramselect in ($paramstring.Keys)) {
if ($($paramstring[$paramselect])) {
Set-Variable -Name $param -Value $SavedParam.$param
foreach ($paramselect in ($paramstring.Keys + $parambool.Keys)) {
$description = $paramstring[$paramselect] + $parambool[$paramselect]
if ($description) {
$val = Get-Variable -Name $paramselect -ValueOnly
Write-host $($paramstring[$paramselect]).padright($padder+20) ": " $val
}
}
foreach ($paramselect in ($parambool.Keys)) {
if ($($parambool[$paramselect])) {
$val = Get-Variable -Name $paramselect -ValueOnly
Write-host $($parambool[$paramselect]).padright($padder+20) ": " $val
Write-host $($description).padright($padder+20) ": " $val
}
}
foreach ($paramselect in ($paramarray.Keys)) {
Expand Down Expand Up @@ -1594,8 +1610,16 @@ function CheckUSBDrive ($USBPath) {
#
#======================================================================================
$PrefSewTypeStar = $preferredSewType | ForEach-Object { "*.$_" }
if ($PrefSewTypeStar.count -eq 0 -or $PrefSewTypeStar -eq $null) {
write-error "Miss configuration of 'preferredSewType', can not continue"
return
}
$SewTypeMatch = $preferredSewType -join '|'
$foldupDirs = $foldupDir + $preferredSewType | ForEach-Object { $_.ToLower() }
if ($foldupDirs.count -eq 0 -or $foldupDir -eq $null) {
write-error "Miss configuration of 'foldupDir', can not continue"
return
}
$allTypesStar = $alltypes | ForEach-Object {"*.$_"}


Expand Down Expand Up @@ -2287,33 +2311,52 @@ if ($CloudAPI -and $CloudAuthAvailable) {


if ($sync) {
$cloudfileremove = $webcollection | Select-Object -ExpandProperty Folders | select-Object -ExpandProperty Files| Where-Object {$_.Name -notin ($mysewingfiles.N)}
$pool = $webcollection
$cloudfileremove = @()
do {
$cloudfileremove += $pool | Select-Object -ExpandProperty Folders | select-Object -ExpandProperty Files| Where-Object {$_.Name -notin ($mysewingfiles.N)}
$pool = $pool | Select-Object -ExpandProperty Folders
} while ($pool.files.count + $pool.folders.count -gt 0)
if ($cloudfileremove.count -gt 10) {
write-host "Removing $($cloudfileremove.count) files from Mysewnet Cloud, this is going to take some time... " -ForegroundColor Yellow
}
$i = 0
$cloudfileremove | ForEach-Object {
# write-host " --Removing from the cloud" $_.Name
Write-Progress -PercentComplete (($i++)*100/$cloudfileremove.count) "Removing files from cloud :" -Status $_.Name
LogAction -File $_.Name -Action "--Deleted-Sync"
DeleteCloudFile -id $_.id | Out-Null
if ($cloudfileremove) {
$cloudfileremove | ForEach-Object {
# write-host " --Removing from the cloud" $_.Name
Write-Progress -PercentComplete (($i++)*100/$cloudfileremove.count) "Removing files from cloud :" -Status $_.Name
LogAction -File $_.Name -Action "--Deleted-Sync"
DeleteCloudFile -id $_.id | Out-Null
}
}
$filestopush = ($mysewingfiles | Where-Object { ($_.Push -and $_.Push.contains('\')) -or ($_.CloudRef -eq $null)}).count

}
else {
$filestopush = ($mysewingfiles | Where-Object { !($_.Push) -and (!($_.CloudRef))}).count
$filestopush = ($mysewingfiles | Where-Object { ($_.Push -and $_.Push.contains('\')) }).count
}

if (-not $KeepEmptyDirectory) {
$emtpyfoldersList = $webcollection | Select-Object -ExpandProperty Folders | where-object {$_.folders.count -eq 0 -and $_.files.count -eq 0 }
if ($emtpyfoldersList.count -gt 0) {
write-host "Clearing Empty Cloud folders : $($emtpyfoldersList.count)"
}
$emtpyfoldersList | ForEach-Object {
ShowProgress "Delete Cloud Folder $($_.Name)"
DeleteCloudFolder -id $_.id | Out-null
$totalfoldersremoved = 0
# BUG need CloudDeleteFolder to manage deletions
#do {
$emtpyfoldersList = @()

$pool = $webcollection
do {
$emtpyfoldersList += $pool | Select-Object -ExpandProperty Folders | Where-Object {$_.files.count -eq 0 -and $_.folders.count -eq 0}
$pool = $pool | Select-Object -ExpandProperty Folders
} while ($pool -and $pool.folders.count -gt 0)

if ($emtpyfoldersList.count -gt 0) {
$totalfoldersremoved += $emtpyfoldersList.count
write-host "Clearing Empty Cloud folders : $($emtpyfoldersList.count) / $totalfoldersremoved"
$emtpyfoldersList | ForEach-Object {
ShowProgress "Delete Cloud Folder $($_.Name)"
DeleteCloudFolder -id $_.id | Out-null
}
}
# } while ($emtpyfoldersList.count -gt 0)
}
write-host "Beginning push to MySewnet: $filestopush files" -ForegroundColor Green
$i = 0
Expand Down Expand Up @@ -2358,41 +2401,16 @@ if ($CloudAPI -and $CloudAuthAvailable) {
}
}
}
<#
if ($sync) {
$mysewingfiles | Out-GridView

$MySewingfiles | ForEach-Object {
$thisfile = $_
if ($thisfile.DirectoryName.length -lt $EmbroidDir.Length) {
$thisfile.DirectoryName
}
$samepath = FindCloudidfromPath -foldername $thisfile.RelPath
if ($thisfile.CloudRef) {
# Need to move
if (""+$samepath.id -ne ""+$thisfile.CloudRef.FolderId) {
ShowProgress -stat "Moving Cloud files" -Area $thisfile.N
LogAction -File $thisfile.N -Action "}}Moved-CloudFolders"
# BUG we need to moka directory if samepath errors
# $folderid = MakeCloudPathID -path $folderpath
MoveCloudFile -fileid $thisfile.CloudRef.Id -toFolderid $samepath.id | Out-Null
}
}
}
}
#>
}





write-host "Calculating size"
ShowProgress "Calculating size"


$librarySizeAfter = 0
$libraryEmbSizeAfter = 0
$byExt = @{}
Expand Down Expand Up @@ -2430,8 +2448,8 @@ if ($Script:savecnt -gt 0) {

}
else {
Write-host " *** Instructions size is : $(niceSize ($librarySizeBefore - $libraryEmbSizeBefore)) **** " -ForegroundColor Green
write-host " *** Embroidary file size is: $(niceSize $libraryEmbSizeBefore) ****"
Write-host " *** Instructions size is : $( ) **** " -ForegroundColor Green
write-host " *** Embroidary file size is: $(niceSize $libraryEmbSizeBefore) ****" -ForegroundColor Green
}
if ($CloudAPI -and $CloudAuthAvailable) {
$updatedMeta = ReadCloudMeta
Expand Down
28 changes: 6 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wanting to manage all the files that you have purchased and downloaded and get t

## Make it work
Once you have download your embroidary files click on the `icon for EmbroideryCollection-Cleanup`<img src="EmbroideryManager.ico" width="24"> and it will look through the download folder and place any downloaded sewing files into the Embroidory folder on your computer. Depending if you are using a USB to transfer the files or using MySewnet Cloud, the script will look at the recently
downloaded files and find the ones that what for your machine, and put them onto the USB stick or push them up the cloud (without wasting space). And it will seperate out the instructions and the instructions on your computer with the embroidary files, but not duplicate them to the USB or cloud. In the process, it will limit the numbers of folders in folders, while still bring some organization to the files.
downloaded files and find the ones that what works for your Embroidery machine, and put them onto the USB stick or push them up the cloud (without wasting space). And it will seperate out the instructions and the instructions on your computer with the embroidary files, but not duplicate them to the USB or cloud. In the process, it will limit the numbers of folders in folders, while still bring some organization to the files.

## How to Install Simple

Expand Down Expand Up @@ -142,34 +142,28 @@ It appears that v1.5 is the current version (as of Feb 2024): https://download.m
- inconsistant treatment of zip vs nested zip for folding directory

# Releases

### 0.6.2
- Added Logging and remove extra debug code
- Fixed saving parameters via JSON for difference between PS 5,6 vs 7
- fix issue with nest cloud folders add/removing of files and empty folders
### 0.6.0
- Added support OpenID using PSAuthClient
- remove user/pw need and caching
- fixed sync moving of files in the cloud
- addressed install script issues
### 0.5.6
- KNOWN ISSUE - MySewnet changed to Auth0 and now the authenication does not work (Fix is process)
- dealing with nested zip (but not recursive zip)
- fixed duplicate files issues
- speed up extract if 7zip is available for zip over 100 MB
- speed up
- add more foldupDir values
- Bug fixes
- fixed up clean up, added pop-up of files it will clean
- copy a nest zip only if 2 deep
- added try/catch on reading zip to avoid corruption errors
- Added upgrade to latest release option (weekly checks)
### 0.5.5
- Bug fixes
### 0.5.4
- Bug fixes with cloud push
- Update Readme to match parameters
- Fixed move files from zip exclusion
- Added Check for version update
### 0.5.3
- More testing and bug files - first public available
### 0.5.2
- Clearing and files of folders in cloud
- interactive setup
### 0.5.1
- Major added Support for USB for people who do not have Mysewnet
Expand All @@ -186,9 +180,6 @@ It appears that v1.5 is the current version (as of Feb 2024): https://download.m
- Change suggested top location to new location outside of OneDrive
- Support for USB drives
- lots of bugs fixed
### 0.1.4.1
- fixed bug in explorer command
- This was a bad version
### 0.1.4
- Started work on using API
- Smaller how to image example
Expand All @@ -201,15 +192,8 @@ It appears that v1.5 is the current version (as of Feb 2024): https://download.m
- Add setup to add Icon to desktop, create folders
- bug fix MyPause
- adjusted Setsize
-
### 0.1.2
- Added Support for Zip inside of Zip
- Adjust the code to start to deal with the end-of-life for the MySewnet Cloud Sync tool.
- Improved some logging
- It does require more manual effort to send the file results to the cloud.
- It still managed the local repository of files but it create a temporary new location for any recent downloads.
- This may actually work better for people who did not use Cloud Sync or have Cloud Sync support but did use Direct USB

### 0.0.2
- Fixed the script name, fixed error messages
### 0.0.1
Expand Down

0 comments on commit 48a0b11

Please sign in to comment.