commit 1bcb09084f9273d61d7fce267be54f49344f0185
parent 57ceacf508d86d134b2e7f349bd49cccdba6ffa9
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Tue, 16 Apr 2024 00:23:36 +0530
Allow URL redirects in mor
Update README - Add a Windows section
Diffstat:
M | README | | | 18 | ++++++++++++++++-- |
M | mor.cmd | | | 22 | +++++++++++++++++++--- |
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/README b/README
@@ -18,6 +18,8 @@ GOALS
* Cross-platform
* Tiny - mor.cmd for windows, mor.sh for *NIX
+NOTE: Check Windows section if you are using the mor.cmd
+
Config File
------------
mor uses .ini files as config files and can be given to mor with -c flag.
@@ -83,8 +85,8 @@ The $platform in the above can be passed to mor as,
mor -Dplatform=linux @lib
-Variable
---------
+Variables
+---------
mor treats any word that starts with '$' as variable and tries to expand it.
@@ -123,6 +125,18 @@ Example
libfoo-2.7=$github/foo/libfoo/releases/download/v26.1/foo-26.1-osx-universal_binary.zip
libfoo-git-2.7=$github/foo/libfoo.git
+Windows
+-------
+- bitsadmin.exe is used to download files in Windows as 'curl' is not available in older versions of Windows.
+
+If you face extreme slowness in downloads, it's probably because some other application is using bitsadmin to download something (like Windows Update)
+
+If you are on a hurry, you can do
+
+ C:\Users\Admin> bitsadmin /reset
+
+to clear all downloads and try running mor again.
+
Bugs/Feature/Todo
-----------------
- Deferencing a $variable second time is disabled. This is for simplicity/security.
diff --git a/mor.cmd b/mor.cmd
@@ -2,6 +2,7 @@
setlocal EnableDelayedExpansion
set mor_version=0.2
set root_dir=%cd%\out\
+for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
rem default values
set /a is_logi=0
@@ -84,9 +85,24 @@ goto :eof
:download_archive
setlocal
echo v [%2] %3
- bitsadmin /rawreturn /transfer "mor %2" %3 "%1\%2%4" || (
- echo fatal: Failed while downloading %3
- exit /b
+ for /f "usebackq" %%i in (`bitsadmin /rawreturn /create "mor:%2"`) do (
+ set job_id=%%i
+ bitsadmin /rawreturn /addfile "%%i" %3 "%~1\%2%4" >>mor.log
+ bitsadmin /setsecurityflags "%%i" 0x0000 >>mor.log
+ bitsadmin /setpriority "%%i" HIGH >>mor.log
+ bitsadmin /setnoprogresstimout "%%i" 30 >>mor.log
+ bitsadmin /resume "%%i" >>mor.log
+ :mor_download_start
+ for /f %%j in ('bitsadmin /info %job_id% ^| findstr TRANSFERRED') do (
+ goto :mor_download_end
+ )
+ for /f %%b in ('bitsadmin /rawreturn /getbytestransferred "%job_id%"') do (
+ <nul set /p"=%%b!CR!"
+ )
+ timeout /t 2 >nul
+ goto :mor_download_start
+ :mor_download_end
+ bitsadmin /rawreturn /complete "%job_id%" >>mor.log
)
endlocal
goto :eof