App restores file encoding from history

sl23
Posts: 233
Joined: 29.01.2013 10:04

App restores file encoding from history

Post by sl23 »

I've been using Rainmeter skins for years, some time ago, I created one that uses WebParser to fetch info from sites. I use this primarily to check sites for app updates. Rainmeter downloads a WebParserDump file, essentially the web site source. I then use basic regexp to get the required info and perform checks against saved version against latest version. Works well for just about any basic html site.

I recently added Python site (https://www.python.org/downloads/windows/) and found the file encoding to be wrong, CT shows encoding is cp1252 and all I am getting is gibberish, no matter how the file is opened, ie, Hex, Text, Binary, Edit Anyway. Changing the encoding is doing nothing. According to the Rainmeter forum, this is an editor issue, topic is here. The first post shows screenshots displaying the problem.
Quote from JSMorley on Rainmeter forum:
WebParser with Debug=2 will read the site, open an empty WebPaserDump.txt file, and uhm... dump the site contents into it. WebParser doesn't try to set any encoding on WebParserDump.txt, it will be seen by editors as ANSI if it contains only ANSI characters and will be seen by editors as UTF-8 w/o BOM otherwise.
So this means that CT is assigning this cp1252 encoding for some reason. But what is worse, is that deleting the file, then performing Debug=2 to download a different site, one I know works fine, then also assigns the same cp1252 encoding to the newly created WebParser.txt file, which it shouldn't do.

I am hoping this can be resolved as it is concerning that encodings can be remembered across files that have been deleted!

Thanks for your help.
Live for an ideal and leave no place in the mind for anything else.
main Alexey
Posts: 3197
Joined: 25.08.2021 18:15

Re: File encoding issue

Post by main Alexey »

yes, cudatext remembers last used encoding for N (by option) filenames, in the "settings/files(SUFFIX).json".
for example, if last opened file was /home/user/cnt.pas, "files.json" can be:

Code: Select all

{
  "|home|user|cnt.pas": {
    "lexer": "Pascal",
    "enc": "cp1251",
    "tab_size": 2,
    "tab_spaces": 1,
    "crt": "0,0,-1,-1,"
  }
}
to reset cp1252 remembering for the same filename, you need to rename a file "WebPaserDump.txt", or to delete "files.json".
does it help?

maybe you want that cudatext's command "File / Close and delete" should remove history entry from "files.json"?
maybe you want to disable the "files.json" usage? you can do it via cudatext options "ui_max_history_......."
sl23
Posts: 233
Joined: 29.01.2013 10:04

Re: File encoding issue

Post by sl23 »

Tbh, I am not sure. So, I suppose my first question has to be, why does CT remember which encoding was last used? Shouldn't text editors open the file with the saved encoding rather than remembering the previous files encoding? I don't understand the need for that tbh. If I open a video file in my media player and choose to view it at 1.3x speed, it wouldn't remember that every time I start that file, I could give a hundred examples of the same thing for more everyday things. Maybe there is a legitimate reason why CT does this, but to me, it seems quite odd?!
Sorry, it's just my lack of knowledge on this causing confusion, not that CT may be right or wrong in doing it this way.
Live for an ideal and leave no place in the mind for anything else.
main Alexey
Posts: 3197
Joined: 25.08.2021 18:15

Re: File encoding issue

Post by main Alexey »

CudaText can be configured to NOT remember last encoding.

Way 1.

Code: Select all

"ui_max_history_files": 0,
(and delete your file "settings/files.json")

Way 2.

Code: Select all

"ui_history_disabled": "e",     
(other letters can also be added after "e").

Note that cp1252 is the fallback encoding for undetected ANSI codepages. it can be changed via user.json option "fallback_encoding".
sl23
Posts: 233
Joined: 29.01.2013 10:04

Re: File encoding issue

Post by sl23 »

I added the "e" will test soon as I can, in the middle of something at present...
Thanks Alexey! :)
Live for an ideal and leave no place in the mind for anything else.
sl23
Posts: 233
Joined: 29.01.2013 10:04

Re: App restores file encoding from history

Post by sl23 »

Tested and ok. But why would the Python site be encoding in cp1252 and showing gibberish?
Live for an ideal and leave no place in the mind for anything else.
main Alexey
Posts: 3197
Joined: 25.08.2021 18:15

Re: App restores file encoding from history

Post by main Alexey »

First give me the link to the file to test it. maybe the file is really 'binary' (eg GZip file).
sl23
Posts: 233
Joined: 29.01.2013 10:04

Re: App restores file encoding from history

Post by sl23 »

ok, heres the resulting WebParser.txt file:

MODERATOR: deleted the file.
Live for an ideal and leave no place in the mind for anything else.
main Alexey
Posts: 3197
Joined: 25.08.2021 18:15

Re: App restores file encoding from history

Post by main Alexey »

this file is PACKED/archived html page. I can enter into the archive by Ctrl+PageDn in the DoubleCommander. then I can look on HTML file of size 560KB inside your 30KB archive. DC dont show the name of archive format.
sl23
Posts: 233
Joined: 29.01.2013 10:04

Re: App restores file encoding from history

Post by sl23 »

Sorry, what does that mean?
Live for an ideal and leave no place in the mind for anything else.
Post Reply