Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressed2TXT and WinXP #3

Open
Zphere1 opened this issue Nov 9, 2020 · 4 comments
Open

Compressed2TXT and WinXP #3

Zphere1 opened this issue Nov 9, 2020 · 4 comments

Comments

@Zphere1
Copy link

Zphere1 commented Nov 9, 2020

I recently used your very useful tool to encode files in a windows shell script (cmd).
It's nice to see that a complete folder and it's file content can be compressed/encoded and later decompressed/decoded in the execution directory of the resulting bat file.
However, you stated compatibility since Win7 and upwards.

Just want to inform you, that your ps code also works under windows xp (SP3) environment with some limitations.
Without modification of the header line in the resulting bat file it will break because you try to switch cp UTF8 via CHCP command inside the cmd/bat file. This is an XP bug; documentations are really difficult to find.
Switching to cp 65001 only works inside the console window itself.
Trying to switch to cp 65001 within any cmd/bat file either breaks further processing or maybe lead to really unexpected results.
Replacing the CHCP value with e.g. 1252 works and makes the batfile go again.
However, when trying to decompress/decode a folder and its file content WinXP extracts only the files in the execution directory.
Till Win7 and upwards also the encoded folder is extracted.

I thought this might be some useful information for you to improve your code in the future.
I assume the cp 65001 setting was made to allow ps to handle multibyte chars in file- or folder names correctly.
Although it seems that you have to waive on this setting in xp, as long as anybody knows his current ACP and uses file/folder names to compress/encode that matches the ACP inside the batch/bat file anything should work flawlessly I think.
You might add some checking procedures?
...just some thoughts of mine.

So far, thanks for your really useful code
Zphere

@AveYo
Copy link
Owner

AveYo commented Nov 7, 2021

chcp 65001 is not really needed indeed

in v6.4 I've switched to 850 just to force console fonts to truetype instead of raster
there should be no impact on functionality otherwise

As for the decompression issue - that's because XP comes with a much older expand.exe tool and cab format dll's
In theory that could be updated to use the ones from 7

@AveYo
Copy link
Owner

AveYo commented Nov 7, 2021

It's not a full year yet since you've opened this issue. Better respond late than never, I guess ;)

@Zphere1
Copy link
Author

Zphere1 commented Nov 13, 2021

Thanks for your response, anyway :-)

I think there's no need to switch to cp850 to overcome the raster font bug of ps.
My batches always look similar like this [Example Snip]:

:_Decode
REM 	There's a documented powershell bug that changes font of cmd window to raster/grid font.
REM 	It seems to depend on the codepage setting and predefined font for cmd.exe in the registry [partic. Consolas].
REM	So, run it in a separate process if cp UTF8 is selected.
REM     https://github.com/microsoft/terminal/issues/367
	SETLOCAL
	FOR /F "tokens=2 delims=:." %%a IN ('CHCP') DO (SET /A _tmpCP=%%a)
REM     This variable replaces the path in the decode section - here in :bat2file:[sed_exe - maybe left out
	SET "0=%_HERE%\%~nx0"
	SET _Cmd=POWERSHELL -nop -c "$f=[IO.File]::ReadAllText($env:0)-split':bat2file\:.*';iex($f[1]); X 1"

	IF "%_tmpCP%"=="65001" (START /WAIT /MIN CMD /C %_CMD%) ELSE (%_cmd% >NUL)
	ENDLOCAL & EXIT /B
EXIT /B
GOTO :EOF

:bat2file: Compressed2TXT v6.1
$k='.,;{-}[+](/)_|^=?O123456789ABCDeFGHyIdJKLMoN0PQRSTYUWXVZabcfghijklmnpqrstuvwxz!@#$&~E<*`%\>'; Add-Type -Ty @'
using System.IO; public class BAT91 {public static void Dec (ref string[] f, int x, string fo, string key) { unchecked {
byte[] b91=new byte[256]; int n=0,c=255,v=91,q=0,z=f[x].Length; while (c>0) b91[c--]=91; while(c<91) b91[key[c]]=(byte)c++;
using (FileStream o=new FileStream(fo,FileMode.Create)) { for (int i=0; i != z; i++) { c=b91[ f[x][i] ]; if (c == 91) continue;
if (v == 91) {v = c;} else {v += c * 91; q |= v << n; if ((v & 8191) > 88) {n += 13;} else {n += 14;} v = 91;
do {o.WriteByte((byte)q); q >>= 8; n -= 8;} while (n>7);} } if (v != 91) o.WriteByte((byte)(q | v << n)); } }}}
'@; cd -lit (Split-Path $env:0); function X([int]$x=1) {[BAT91]::Dec([ref]$f,$x+1,$x,$k); expand -R $x -F:* .; del $x -force}

:bat2file:[ sed_exe
... ... ...

@AveYo
Copy link
Owner

AveYo commented Nov 14, 2021

It's not just for the raster font. Some localized commands can get in a way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants