                     __          _______           _
                     \ \        / /_   _|         | |
                      \ \  /\  / /  | |  _ __  ___| |_
                       \ \/  \/ /   | | | '_ \/ __| __|
                        \  /\  /   _| |_| | | \__ \ |_
                         \/  \/   |_____|_| |_|___/\__|

                           *** Windows Installer ***

0. Purpose
   -------
   Installing Windows 7-10 via:
   - automating the launch of the standard Windows setup program setup.exe with
     command line keys. To install new editions of Windows 10, the method of
     substitution of the standard library winsetup.dll is used.
   - deploying Windows to a hard disk (both with the possibility of partitioning it, and on
     already prepared) or into a VHD container using the wimlib-imagex.exe program and
     then adding to the download list.

1. Terminology
   -----------
                            Distribution folder (PD)
                            ~~~~~~~~~~~~~~~~~~~~~~~~
   The folder that contains:
   - installation file with the WIM, ESD, SWM extension. This is usually "install.esd"
   - description file (optional) {see "Notes" about description file format }
   - $OEM$ folder (optional)
   - unattend.xml answer file (optional)
   - installation kit setup.exe (optional)

   It is allowed the presence of multiple installation files with description files in the PD.

                              Shared folder (OP)
                              ~~~~~~~~~~~~~~~~~~
   The folder that contains:
   - distribution folders
   - $OEM$ folder (optional)
   - unattend.xml answer file(s) (<any_name>.xml)

2. Concept
   -------
   There are three options for the location of the PD:

                                  Classical
                                  ~~~~~~~~~
   The OP is located in an arbitrary place on the flash drive. For example:

   F:\
      OP\
         PD\
         PD\
         PD\
         ...

                                  Portable
                                  ~~~~~~~~
   The OP is called "WInstall" and is located in the folder WInst with the installation 
script "WInst.cmd". For example:

   F:\
      Folder\
             WInst\
                   WInstall\
                            PD\
                            PD\
                            PD\
                            ...
                   WInst.cmd


                                 Arbitrary
                                 ~~~~~~~~~
   There is no OP folder, PDs are located anywhere on the flash drive. For example:

   F:\
      Folder\
             PD
      Folder1\
              Folder2\
                      PD
                      PD
                      Folder3\
                              PD

3. Execution
   ---------
                              Search and display
                              ~~~~~~~~~~~~~~~~~~
   First, a search is performed for PDs located in the "classic" version.
The file dirlist.txt is used to indicate the location of the OP.
For example, we have a USB stick with the following folder structure:

   F:\
      Install\
              Windows\
                      Win7x86\
                      Win81x64\
                      Win10x64\

   In this example, the OP is F:\Install\Windows\
   We discard the drive letter with a colon and a trailing slash, we get "\Install\Windows"
   This is what we write to the dirlist.txt file:

   \Install\Windows

   If there is more than one OP, then add the corresponding lines to dirlist.txt.

   It is allowed to indicate PD directly in dirlist.txt (this is advisable if PD
contains multiple installation files). Taking the folder structure from the example above,
then we write to dirlist.txt:

   \Install\Windows\Win7x86\@
   \Install\Windows\Win81x64\@
   \Install\Windows\Win10x64\@

   Next, a search is performed for PDs located in the "portable" option (the WInstall folder).

   If the search in the options "classic" and "portable" did not return any results and there is
a file fudlist.txt (see below) in the folder of the program, then information about distributions
is taken out of it.

   Display options for found distributions:
- if a description file exists for the installation file, then its contents are displayed
- if there is no description file, then information is taken from the first index of the distribution

                           Additional features
                           ~~~~~~~~~~~~~~~~~~~
   Switch display mode: "version/path" - switch view from information from
                                         first index to full path to
                                         distribution kit.
   Select a distribution kit manually - choose a distribution file yourself (a file with
                                        extension ESD, WIM, SWM).
   Search for distributions on selected disks - search on selected disks for files with
                                                extension WIM, ESD, SWM and size
                                                more than 1,000,000,000 bytes.
   Pre-partitioning the disk - partition a new one (or without saving data)
                               drive using diskpart scripts.
   Create / Open VHD (X) - create a new / open an existing VHD (X) file and
                           connect it to the system for later installation
                           into it Windows.
   Maintenance - add a partition / VHD container to the Windows bootloader;
                 integrate drivers / installation packages;
                 remove / roll back installed drivers;
                 restore partition / disk boot records.

   Search is mainly used for "arbitrary" location of the PD. Search 
results are written to the fudlist.txt file and can be used for subsequent
WInst launches (unlike dirlist.txt, contains full paths (no disk) to
found distributions). The fudlist.txt file can be converted to dirlist.txt. For
rename this:
  fudlist.txt -> fud2dir.txt (or just fud2dir) to overwrite dirlist.txt
  fudlist.txt -> fud4dir.txt (or just fud4dir) to add to dirlist.txt
and start "WInst.cmd".

   Installer warning about not being able to use VHD partition for Windows 
  installation should be ignored.

   "Fix boot" option:
   * MBR/PBR (PBR) - update only boot records.
   * MBR/PBR + update BCD - update boot records and BCD.
   * Advanced Boot Options - enable the "Advanced Boot Options" menu at startup.

   - for the "WINDOWS" partition, the partition boot record is updated;
   - for the "BOOTLOADER" partition, the boot record of the partition and the MBR of the disk is updated,
     containing the section "BOOTLOADER";
   - after applying "Advanced Boot Options" at the root of the "WINDOWS" section, it is created
     file "AdvBootOpt_off.cmd" to disable the option.

   During integrating drivers using WInst in the "\Windows\Temp" folder of the target system
a file "WInst_Add_Drivers.bak" is created containing a list of drivers installed
before integration. Thus, rolling back of installed drivers is removing all
drivers that are not in this list.

				Installation options
                                ~~~~~~~~~~~~~~~~~~~~
   Distribution    - Switching (toggle) "version/path" view
   $OE$ folder     - It can be located in three places: PD, OP, WInstall. Respectively, it
                     will displayed as: $OEM$, .. \$OEM$, _WInst _\$OEM$
                     If all three options exist, you can manually select the one you want.
   The answer file - It is similar to the $OEM$ folder. It will be displayed as:
                     unattend.xml, .. \unattend.xml, _WInst_\unattend.xml
                     The OP and WInstall folders can contain several files with the xml extension,
                     the desired one can be selected manually.
   Installer - If setup.exe exists in the PD, it will be offered for launch.
                  You can manually select the built-in setup.exe.
                  If the "setup_x86.exe" variables and/or
                  "setup_x64.exe" containing the path to the unpacked setup.exe package
                  installation, then this particular kit will be used as
                  built-in installer.

   Integrity check - Check of the installation file will be launched before installation.
   Reboot - you can cancel a reboot after installation or distribution deployment.
   EI.cfg license - Switching between Volume/Retail
   Language selection - The installation language is taken from the first index of the distribution or
                        can be manually selected.
   Winsetup.dll selection method - the choice of Winsetup.dll is "direct" by default.
                                   If during the installation process appears error 
                                   "License agreement not found", then you can change to "reverse".


4. Deployment
   ----------
   The essence of the deployment is:
   - unpacking the distribution file to a hard disk partition (or to a VHD container)
   - adding a new item to the Windows boot menu (or creating this menu)

   Procedure:
   1. Select the partition where the distribution will be unpacked;
   2. Select the partition where the bootloader is located (or will be created);
   3. Select the bootup type.

   Partitions must have a file system (RAW cannot be used)
   Partition selecting window for unpacking the distribution contains [WINDOWS = ...] in the "header"
   - if the partition already has Windows, then you will be prompted to format the partition
   Partition selecting window for installing the bootloader contains [BOOTLOADER = ...] in the "header"
   - you can do not install/not change the bootloader
   Bootup type can be:
   * ALL - Boot the system in both BIOS and UEFI mode
   * BIOS - boot the system in BIOS mode only
   * UEFI - boot the system only in UEFI mode

				  Deployment options
                                  ~~~~~~~~~~~~~~~~~~

   New BCD - create a new BCD configuration file (instead of adding a new entry in
             existing configuration) and update the bootloader files.
   Drivers - operations with drivers after deployment.
   Reboot - reboot after completion of deployment.

   Operations with drivers:
   * Addition - select a folder with unpacked drivers that will be
                integrated into deployed Windows. Additionally the folder can
                contain Windows installation packages (files with ".msu" or ".cab"
                extensions), which will also be integrated.
   * Uninstall - remove all third-party drivers from the deployed Windows.
   * Delete+add - a combination of the previous items.

5. Composition:
   -----------
   docs       - folder with help files.
   packs      - folder with installation kits and auxiliary utilities.
   schemes    - folder with diskpart scripts for "Pre-partition disk".
   WInst.cmd  - startup file.

   Optional:
   ~~~~~~~~
   dirlist.txt  - list of OPs and PDs for searching by "classic" variant.
   settings.txt - settings file for changing the values of the parameters used
                  by default.
   WInstall     - a folder for placing the common $OEM$, unattend.xml and PD for the "portable"
                  variant of the location of the PD.

6. Notes
   -----
- designed to run:
  * for installation via setup.exe: from under WinPE 7-10 x86/x64
  * for installation via deployment: from under Win7-10 x86/x64 and WinPE 7-10 x86/x64
- search for folders from dirlist.txt and files from fudlist.txt is performed across all disks
- in the case of "arbitrary" location of the PD, you can also use the common $OEM$ and
  unattend.xml from WInstall folder
- during "Deployment" and "Maintenance", backup copies of the BCD configuration file are created
   in folders "\Boot\{WInst}.bak" and "\EFI\Microsoft\Boot\{WInst}.bak"
  for BIOS and UEFI respectively.

  Description file format:
  - coding WIN-1251
  - description file name = installation file name + "txt" extension
    For example: "install.esd.txt"
  - content:
    * first line - description of the installation itself
    * the following lines are revision descriptions (optional) in the "N=Title" format
    For example, the contents of "install.esd.txt":

    Windows 7 SP1 (x86-x64) Russian

    1=Windows 7 (x86)    Ultimate
    2=Windows 7 (x86_64) Ulimate
    7=Windows 7 (x86)    Home Basic
    8=Windows 7 (x86_64) Home Basic

  When deploying a revision for which there is a description in the description file, a new item
in the Windows boot menu will be named as the revision description, and not standard
"Windows 7" or "Windows 10". If this edition is deployed on one PC
several times, then the index [N] will be added to the name, where N = 2.3, etc.

__________________
(c) 2018, Ander_73

