Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.69k stars 1.08k forks source link

BUG: Script does not perform all functions #272

Closed LukasKysela closed 4 years ago

LukasKysela commented 4 years ago

Script does not perform all functions. If something is disabled and then the script runs and then somethings enabled and the script is run again, the setting is ignored and the change is not made. These are functions that are not at the beginning of the configuration file .preset only.

Problem is maybe in function for preset file line parsing.

Disassembler0 commented 4 years ago

Paste or attach your preset. If this is about custom tweaks, paste or attach the functions too.

LukasKysela commented 4 years ago

I am not able to edit the main script (currently I have no way to test it). But I know how to adjust the format of the Preset file to make the functions work.

This format not apply function (char "_" symbolized spaces for bad GitHub ignored many spaces): # HideTaskbarSearch___________ShowTaskbarSearchIcon______# ShowTaskbarSearchBox

This is format ok:

# HideTaskbarSearch
ShowTaskbarSearchIcon
# ShowTaskbarSearchBox
Disassembler0 commented 4 years ago

Multiple tweaks on the same line are not supported. See https://github.com/Disassembler0/Win10-Initial-Setup-Script#presets

one function name per line, no commas or quotes, whitespaces allowed, comments starting with #

Everything after the first # is part of the comment until the end of the line. That's also how PowerShell and many other languages work (though unlike the preset format, most of the languages support also inline comments). So your second snippet is the correct and the only way how presets should be written. In the first, you're commenting the whole part after first #, no matter how many spaces or other # are on the line.

The second column of Default.preset with commented tweaks reverting to the default behavior is there just for documentation purposes and to make searching for undo-tweaks easier. If you actually want to use such tweak, you still need to put it on a separate line.

LukasKysela commented 4 years ago

Okay. But then the choices that aren't accept at after the first row position. Try to test it. Quite often I reinstall the OS and for some time I struggled to edit the function in the psm1 file to make it work but I didn't find a solution. And as a workaround was to edit the preset file. When I wrote about this problem before, you blocked me under my original nickname so I couldn't contribute. I waited about two years that hopefully the thing would be fixed and other users could figure it out, but probably no one still noticed, so I had to create a second account to write repeatedly to you. Your script is otherwise good but I don't like to edit the preset file after every update to make it work. Occasionally, I try to find a better function that would fix the parsing preset file once and for all.

You have now closed the topic again. So I have no idea what the problem is. I do not speak English very well (I translate it using a translator) so I can write it to you in Czech if you speak Czech. According to the e-mail you are probably Czech.

And I have no idea why I was blocked when I just described the problem.

Disassembler0 commented 4 years ago

hopefully the thing would be fixed and other users could figure it out, but probably no one still noticed

No, the problem is that you are doing it wrong or somehow fundamentally misunderstand how the preset parsing works. There is nothing to fix. This is exactly what I wrote you the first time and tried to explain what should be done instead. After several rounds of your inability to comprehend you've started with insults, so you were blocked.

But then the choices that aren't accept at after the first row position.

Yes. That's what one function name per line means.

I struggled to edit the function in the psm1 file to make it work but I didn't find a solution. And as a workaround was to edit the preset file.

You shouldn't touch ps1 and psm1 at all. Only the preset file needs to be edited. The whole point of the script since version 2 is that it applies only those tweaks which you ask it to. Originally, there was just one way how to tell the script which tweaks to run - via command line params - this become too cumbersome with >20 tweaks, so a simple flat file was used instead. Nowadays the default preset is there for both convenience and documentation purposes - it's mostly commented list of all tweaks and their counterparts with curated set of enabled tweaks which are applied if the user doesn't provide their own preset. All this is described in Advanced usage section of FAQ.

I don't like to edit the preset file after every update to make it work

That's why you should create and keep your own preset with your own selection tweaks. One on many ways how to do it is described in Maintaining own forks section of FAQ.

I can write it to you in Czech if you speak Czech

I'd rather you don't, because if we keep it in English, somebody else might be able to explain better. However if the whole problem stems from the inability to translate properly, here's a thorough explanation of how preset work in Czech. 👇


Soubory ps1 a psm1 není v současnosti potřeba vůbec modifikovat. Ve verzi 2 byly tweaky přesunuty do jednotlivých funkcí a uživateli bylo umožněno vybrat, které tweaky chce spustit. To se dalo udělat buď předáním názvů funkcí do parametrů příkazové řádky nebo vytvořením souboru presetu. V té době bylo vše obsaženo v jediném souboru, takže výchozí preset existoval jako pole (array) na začátku ps1 souboru. Spousta lidí, včetně tebe, to řešila úpravou toho pole. Zhruba v té době jsi mi psal poprvé s podobným bugreportem, ze kterého vyplynulo, že máš chyby v syntaxi toho pole (a ty chyby, které stále děláš i teď, jsou velmi podobné). Ve verzi 3 se výchozí preset úplně přesunul do odděleného souboru, pro snazší editaci a sledování změn.

Soubor presetu má velmi specifický a velmi jednoduchý formát, který je nutno dodržovat. Pravidla jsou následující:

Tvé problémy pramení z toho, že tento formát nedodržuješ nebo že očekáváš, že parser "pochopí" něco co v těchto pravidlech není. Nedodržení prvního a posledního pravidla vyústí přesně v to, co reportuješ v #272 a #273.

Parser pak jede řádek po řádku a dělá:

  1. Načti celý řádek.
  2. Najdi první výskyt znaku "#" a vše, co je za ním, zahoď. Pokud žádné "#" na řádku není, řádek zůstává nezměněn.
  3. Z toho, co zbylo z předchozího kroku odstraň bílé znaky ze začátku a konce (funkce Trim()), tj. z řetězce    Bla   Bla    se odstraní první a poslední tři mezery, ale ty uprostřed zůstanou. Pokud žádné bílé znaky na začátku a konci nejsou, řádek zůstává nezměněn.
  4. To, co zbude po všech předchozích krocích spusť jako výraz. (Je to trochu zjednodušené, protože ve skutečnosti se ty tweaky nespouští hned, a navíc ještě existuje možnost tweaky přes znak vykřičníku odebírat, ale tím tě teď nechci mást.)

Takže pokud mám preset

# Sekce1
EnableBla1    # DisableBla1
# EnableBla2    DisableBla2

# Sekce2
EnableBla3
EnableBla4   DisableBla4

Tak parser čte řádek po řádku a vykonává

# Sekce1

⇒ Vše od prvního "#" dál je komentář. Mezi začátkem řádku a prvním "#" není nic, takže se nic neprovede.

EnableBla1    # DisableBla1

⇒ Vše od prvního "#" dál je komentář. Mezi záčátkem řádku a prvním "#" je EnableBla1     (se čtyřmi mezerami na konci). Z toho se odmažou přebytečné bílé znaky (zde pouze na konci, protože na začátku žádné nejsou) a zbyde EnableBla1, které se spustí.

# EnableBla2    DisableBla2

⇒ Vše od prvního "#" dál je komentář. Mezi začátkem řádku a prvním "#" není nic, takže se nic neprovede, a to ani přes to, že EnableBla2 a DisableBla2 mohou být platné názvy tweaků.

⇒ Prázdný řádek, takže se nic neprovede.

# Sekce2

⇒ Vše od prvního "#" dál je komentář. Mezi začátkem řádku a prvním "#" není nic, takže se opět nic neprovede.

EnableBla3

⇒ Žádné "#" ani žádné bílé znaky nejsou, takže se rovnou spustí EnableBla3.

EnableBla4   DisableBla4

⇒ Žádné "#" není, takže se vezme celý řetězec EnableBla4   DisableBla4. Žádné bílé znaky na začátku ani na konci tohoto řetězce nejsou, takže se spustí celé EnableBla4   DisableBla4 jako jeden výraz, což pro PowerShell znamená "Spusť funkci EnableBla4 s parametrem DisableBla4." a protože EnableBla4 žádné parametry nepřijímá, bude to DisableBla4 ignorováno. Pokud ho chci taky spustit jako tweak, musím ho napsat na řádek zvlášť.

Takže tvůj příklad

# HideTaskbarSearch           ShowTaskbarSearchIcon      # ShowTaskbarSearchBox

udělá úplně přesně to, co po něm chceš. Vše od prvního "#" dál je komentář. Mezi začátkem řádku a prvním "#" není nic, takže se nic neprovede. Proto to musíš rozepsat tak, jak píšeš v tom druhém případu

# HideTaskbarSearch
ShowTaskbarSearchIcon
# ShowTaskbarSearchBox

Kde se druhý řádek zpracuje a spustí, protože ten jako jediný zakomentovaný není.

Je už teď jasnější, jak mají presety vypadat a jak fungují?


cc @r3incarnat0r, @Conder000, @LiBOSS-CZ, as you have some contributions in the script and also speak the language of our Slavic tribe, so maybe you can help me out with additional explanation if this one fails.

Disassembler0 commented 4 years ago

Is the explanation satisfactory, @LukasKysela?