From a27dafd2d79e20b93d83a799f881070441e566cd Mon Sep 17 00:00:00 2001
From: "Michael H.G. Schmidt" <michael@schmidt2.de>
Date: Sun, 1 Jan 2023 15:16:29 +0100
Subject: [PATCH] added apps folder

---
 apps/Download-AppxFromStore.ps1       | 63 +++++++++++++++++++++++++++
 software/download-from-ftp.cmd        |  1 +
 software/download-from-source.cmd     |  1 +
 software/upload-to-ftp-singlefile.cmd |  1 +
 software/upload-to-ftp.cmd            |  1 +
 5 files changed, 67 insertions(+)
 create mode 100644 apps/Download-AppxFromStore.ps1

diff --git a/apps/Download-AppxFromStore.ps1 b/apps/Download-AppxFromStore.ps1
new file mode 100644
index 0000000..321c19b
--- /dev/null
+++ b/apps/Download-AppxFromStore.ps1
@@ -0,0 +1,63 @@
+<#
+  Original script taken from: https://github.com/MattiasC85/Scripts/blob/master/OSD/Download-AppxFromStore.ps1
+#>
+
+Param (
+  [Parameter(Mandatory=$True)] [string] $StoreURL
+)
+
+if ($StoreURL.EndsWith("/")) {
+  $StoreURL=$StoreURL.Remove($StoreUrl.Length-1,1)
+}
+
+$wchttp = [System.Net.WebClient]::new()
+$URI = "https://store.rg-adguard.net/api/GetFiles"
+$myParameters = "type=url&url=$($StoreURL)"
+$wchttp.Headers[[System.Net.HttpRequestHeader]::ContentType]="application/x-www-form-urlencoded"
+$HtmlResult = $wchttp.UploadString($URI,$myParameters)
+
+$start=$HtmlResult.IndexOf("<p>The links were successfully received from the Microsoft Store server.</p>")
+write-host $start
+
+if ($Start -eq -1) {
+  write-host "Could not get the links, please check the StoreURL."
+  exit
+}
+
+$TableEnd=($HtmlResult.LastIndexOf("</table>")+8)
+$SemiCleaned=$HtmlResult.Substring($start,$TableEnd-$start)
+
+$newHtml=New-Object -ComObject "HTMLFile"
+try {
+  # This works in PowerShell with Office installed
+  $newHtml.IHTMLDocument2_write($SemiCleaned)
+} catch {
+  # This works when Office is not installed    
+  $src = [System.Text.Encoding]::Unicode.GetBytes($SemiCleaned)
+  $newHtml.write($src)
+}
+
+$ToDownload=$newHtml.getElementsByTagName("a") | Select-Object textContent, href
+
+$LastFrontSlash=$StoreURL.LastIndexOf("/")
+$ProductID=($StoreURL -split "/").split()[-2]
+
+if (!(test-path "$ProductID")) {
+    write-host "Creating directory $ProductID"
+    try {
+        New-Item -ItemType Directory "$ProductID" -ErrorAction Stop | Out-Null
+    } catch {
+        write-host "Failed to create directory.$([System.environment]::NewLine)$_"
+        write-host "Exiting..."
+        exit
+    }
+}
+
+Foreach ($Download in $ToDownload) {
+  Write-host "Downloading $($Download.textContent)..."
+  $wchttp.DownloadFile($Download.href, "$ProductID\$($Download.textContent)")
+}
+
+write-host "---------------------------------------"
+write-host "Download is complete. Your files are in directory [ $ProductID ] ..." 
+
diff --git a/software/download-from-ftp.cmd b/software/download-from-ftp.cmd
index c5b7c19..159c285 100644
--- a/software/download-from-ftp.cmd
+++ b/software/download-from-ftp.cmd
@@ -83,3 +83,4 @@ echo   LISTFILE = basic, browser, optional or other
 echo.
 
 :END
+
diff --git a/software/download-from-source.cmd b/software/download-from-source.cmd
index 8ddae57..435fd0b 100644
--- a/software/download-from-source.cmd
+++ b/software/download-from-source.cmd
@@ -62,3 +62,4 @@ echo   LISTFILE = basic, browser or optional
 echo.
 
 :END
+
diff --git a/software/upload-to-ftp-singlefile.cmd b/software/upload-to-ftp-singlefile.cmd
index e96bbf3..9870899 100644
--- a/software/upload-to-ftp-singlefile.cmd
+++ b/software/upload-to-ftp-singlefile.cmd
@@ -54,3 +54,4 @@ echo "usage: %0 <UPLOADFILE>"
 echo.
 
 :END
+
diff --git a/software/upload-to-ftp.cmd b/software/upload-to-ftp.cmd
index d9f38bb..aedf4e9 100644
--- a/software/upload-to-ftp.cmd
+++ b/software/upload-to-ftp.cmd
@@ -75,3 +75,4 @@ echo   LISTFILE = basic, browser, optional or other
 echo.
 
 :END
+