// Import Personal Configuration from WinEdt 9

    Requires(20161103);
    IfStr('%b','%B','=',>
      !"Prompt('You are using Global Configuration!');Exit;");
    IfStr('%$("Old-AppData");','','=',>
      !"Prompt('No installation of WinEdt 9 found!');Exit;");

    // Extra Tasks
    Exe('%b\Config\Migrate\MigrateClean.edt');
    IfStr('%$(|Migrate-Issues|);','1','=',>
      !"Release('%$(|Migrate-Issues|);');Exit;",>
      !"Release('%$(|Migrate-Issues|);');");

    Prompt("This macro imports your personal configuration from WinEdt 9...%\>
All files (and project) will be closed to make it faster.%\%\>
                            Continue?",1,0);

    PushTagsandRegisters;

    StartWorking('Importing Configuration from WinEdt 9...');
    ProcessMessages;
    SaveSettings;

    JMP(!"Migrate_Start");

:Migrate_Do:: =======================================================

    WrL('=========================================================%\');
    WrL('%!3.ini%\');

    // Read the old file!
    ReadFile('%b\ConfigEx\%!3.ini',0);

    // Update!
    Assign("Folder","Update");
    Call('Migrate_Execute');

    // Migrate!
    Assign("Folder","Migrate");
    Call('Migrate_Execute');

    // Upgrade!
    Assign("Folder","Upgrade");
    Call('Migrate_Execute');

    // Write the modified file!
    WriteFile('%b\ConfigEx\%!3.ini','%!0');

Return;

:Migrate_Execute:: ==================================================

    LetRegNum(7,1);
    Loop(!`>
      IfFileExists('%B\Config\%$("Folder");\%!3_new%!7.dat',>
        !|ReadFile('%B\Config\%$("Folder");\%!3_old%!7.dat',4);>
          ReadFile('%B\Config\%$("Folder");\%!3_new%!7.dat',5);>
          Call('Migrate_Sub');>
          LetRegNum(7,%!7+1);|,>
        !|Stop;|);`);

Return;

:Migrate_Sub:: ======================================================

    SubstituteInString('%!0','%!4','%!5',10);
    IfOK(!"WrL('---------------------------OK!---------------------------%\%\>
The following lines%\%\%!4%\have been substituted with%\%\%!5');",>
         !"Call('Migrate_Sub_Fail');");

Return;

:Migrate_Sub_Fail:: =================================================

    FindInString("%!0","%!5",-1,-1,10);
    IfOK(!"WrL('---------------------------OK!---------------------------%\%\>
The following lines%\%\%!5%\were already up-to-date%\');",>
         !"Call('Migrate_Fail');");

Return;

:Migrate_Fail:: =====================================================

    Assign('Warn-Found','1');
    LetReg(4,'The following lines%\%\%!4%\as well as the following%\%\%!5');
    LetRegNum(8,1);
    Loop(!`>
      IfFileExists('%B\Config\%$("Folder");\%!3_upd%!7-%!8.dat',>
        !|ReadFile('%B\Config\%$("Folder");\%!3_upd%!7-%!8.dat',5);>
          FindInString("%!0","%!5",-1,-1,10);>
          IfOK(!"WrL('---------------------------OK!---------------------------%\%\>
The following lines%\%\%!5%\were already up-to-date%\');>
                 Assign('Warn-Found','0');>
                 Stop;",>
               !"LetRegNum(8,%!8+1);>
                 LetReg(4,'%!4%\as well as the following%\%\%!5');");|,>
        !|Stop;|);`);
    SubstituteInString("%!4","%\as well as the following%\%\%!5","",10,4);
    IfStr('%$("Warn-Found");','1',!'=',>
      !|WrL('------------------------WARNING!!------------------------%\%\>
%!4%\have not been found...%\>
A correctly imported %!3.ini should contain the following lines%\%\%!5');>
        LetRegNum(9,%!9+1);|);

Return;

:Migrate_Start:: ====================================================

// Copy Old Files ===================================================

    // Close current Project
    ClosePrj(1,1,1);

    // Discard unneeded files
    LetReg(2,"<{{User Profile@{ Build}\.dat}|{Config\\Update+{$Numeric$}\\}|{Samples\\}}");

    ListFolderFiles(1,'%$("Old-AppData");','*|bak;sav;dnt;log',1,1);
    LstEnum('%!1','%\');
    LstGetCount(1);
    Repeat(%!1,>
      !|LstGetItem(3,%!c-1);>
        FindInString('%!3','%!2',-1,-1,1);>
        IfOK(!'Relax;',!'CopyFile(`%$("Old-AppData");\%!3`,`%b\%!3`,1,1);');>
        ProcessMessages;>
       |);
    LstRelease;

    // Need to reload images?
    ListFolderFiles(1,'%b\Bitmaps\Images','.png',0,1);
    IfStr('%!1','','<>',!'ReloadImages;');

// Cleanup ==========================================================

    ListFolderFiles(1,'%b','.ini',1,1,1);
    LstEnum('%!1','%\');
    LstGetCount(1);
    Repeat(%!1,>
      !|LstGetItem(3,%!c-1);>
        IfFileExists("%B\%!3",>
          !"ReadFile('%b\%!3',4);>
            ReadFile('%B\%!3',5);>
            IfStr('%!4','%!5',!'=',!'DeleteFile(`%b\%!3`);');>
            IfStr('%!4',!'',!'=',!'DeleteFile(`%b\%!3`);');");>
        LetReg(8,'%b\%!3');>
        Loop(!`>
          GetFilePath("%!8",8);>
          IfStr('%b','%!8',!'>=',!'Stop;',>
            !'RemoveDirectory("%!8");>
              IfOK(!"Relax;",!"Stop;");');`);>
        ProcessMessages;>
       |);
    LstRelease;

    ListFolderFiles(1,'%b','.edt',1,1,1);
    LstEnum('%!1','%\');
    LstGetCount(1);
    Repeat(%!1,>
      !|LstGetItem(3,%!c-1);>
        IfFileExists("%B\%!3",>
          !"ReadFile('%b\%!3',4);>
            ReadFile('%B\%!3',5);>
            IfStr('%!4','%!5',!'=',!'DeleteFile(`%b\%!3`);');>
            IfStr('%!4',!'',!'=',!'DeleteFile(`%b\%!3`);');");>
        LetReg(8,'%b\%!3');>
        Loop(!`>
          GetFilePath("%!8",8);>
          IfStr('%b','%!8',!'>=',!'Stop;',>
            !'RemoveDirectory("%!8");>
              IfOK(!"Relax;",!"Stop;");');`);>
        ProcessMessages;>
       |);
    LstRelease;

// Migrate ==========================================================

    // Create the Log File
    OpenOutput('%b\Migrate.log');

    // Insert the general information
    GetDate(9, 'dddd, mmmm d, yyyy "at" hh:nn'); // Date Stamp
    WrL('Migrate.log%\');
    WrL('%!9%\%\');

    LetRegNum(9,0);
    ListFolderFiles(1,'%b\ConfigEx','.ini',0,1);
    LstEnum('%!1','%\');
    LstGetCount(1);
    Repeat(%!1,>
      !|LstGetItem(2,%!c-1);>
        GetFileName('%!2',3);>
        Call('Migrate_Do');>
        ProcessMessages;>
       |);
    LstRelease;
    Assign('Warn-Count','%!9');

    // Save the Log File
    CloseOutput;

    // Extra Tasks
    Exe('%b\Config\Migrate\MigrateExtra.edt');
    Exe('%b\Config\Upgrade\UpgradeExtra.edt');
    Exe('%b\Config\Migrate\MigrateCleanup.edt');

// Rebuild All ======================================================

    LoadConfig("ConfigEx\Colors.ini");
    LoadConfig("ConfigEx\Images.ini");
    LoadConfig("ConfigEx\MainMenu.ini");
    LoadConfig("ConfigEx\PopupMenus.ini");
    LoadConfig("ConfigEx\Toolbar.ini");
    LoadConfig("ConfigEx\GUI.ini");
    LoadConfig("ConfigEx\DocTabs.ini");
    LoadConfig("ConfigEx\DocList.ini");
    LoadConfig("ConfigEx\StatusBar.ini");
    LoadConfig("ConfigEx\Bookmarks.ini");
    LoadConfig("ConfigEx\Input.ini");
    LoadConfig("ConfigEx\Tree.ini");
    LoadConfig("ConfigEx\Gather.ini");
    LoadConfig("ConfigEx\Folding.ini");
    LoadConfig("ConfigEx\Wrapping.ini");
    LoadConfig("ConfigEx\Paragraphs.ini");
    LoadConfig("ConfigEx\Environments.ini");
    LoadConfig("ConfigEx\WordCount.ini");
    LoadConfig("ConfigEx\Font.ini");
    LoadConfig("ConfigEx\Tabs.ini");
    LoadConfig("ConfigEx\Caret.ini");
    LoadConfig("ConfigEx\Fonts.ini");
    LoadConfig("ConfigEx\Editor.ini");
    LoadConfig("ConfigEx\MouseInterface.ini");
    LoadConfig("ConfigEx\Modes.ini");
    LoadConfig("ConfigEx\Defaults.ini");
    LoadConfig("ConfigEx\Templates.ini");
    LoadConfig("ConfigEx\Find.ini");
    LoadConfig("ConfigEx\Find in Files.ini");
    LoadConfig("ConfigEx\Replace.ini");
    LoadConfig("ConfigEx\Incremental Search.ini");
    LoadConfig("ConfigEx\Errors.ini");
    LoadConfig("ConfigEx\Delimiters.ini");
    LoadConfig("ConfigEx\AutoComplete.ini");
    LoadConfig("ConfigEx\ActiveStrings.ini");
    LoadConfig("ConfigEx\Abbreviations.ini");
    LoadConfig("ConfigEx\Language.ini");
    LoadConfig("ConfigEx\Unicode.ini");
    LoadConfig("ConfigEx\Sorting.ini");
    LoadConfig("ConfigEx\TranslationTables.ini");
    LoadConfig("ConfigEx\Dictionaries.ini");
    LoadConfig("ConfigEx\Spelling.ini");
    LoadConfig("ConfigEx\Suggestions.ini");
    LoadConfig("ConfigEx\IgnoredText.ini");
    LoadConfig("ConfigEx\SpellingErrors.ini");
    LoadConfig("ConfigEx\CompoundedWords.ini");
    LoadConfig("ConfigEx\ColorEffects.ini");
    LoadConfig("ConfigEx\BackgroundSchemes.ini");
    LoadConfig("ConfigEx\ColorGrid.ini");
    LoadConfig("ConfigEx\Selections.ini");
    LoadConfig("ConfigEx\FilterSets.ini");
    LoadConfig("ConfigEx\Switches.ini");
    LoadConfig("ConfigEx\Keywords.ini");
    LoadConfig("ConfigEx\Columns.ini");
    LoadConfig("ConfigEx\Backup.ini");
    LoadConfig("ConfigEx\AutoSave.ini");
    LoadConfig("ConfigEx\Folders.ini");
    LoadConfig("ConfigEx\FileStatus.ini");
    LoadConfig("ConfigEx\Project.ini");
    LoadConfig("ConfigEx\Forms.ini");
    LoadConfig("ConfigEx\Sounds.ini");
    LoadConfig("ConfigEx\Preferences.ini");
    LoadConfig("ConfigEx\Options.ini");
    LoadConfig("ConfigEx\Events.ini");
    LoadConfig("ConfigEx\Config.ini");
    LoadConfig("ConfigEx\PrintSchemes.ini");
    LoadConfig("ConfigEx\Print Schemes\PrintDefault.ini");
    IfFileExists("%b\ConfigEx\UserPreferences.ini",!'LoadConfig("%b\ConfigEx\UserPreferences.ini");');
    IfFileExists("%b\ConfigEx\Private.ini",!'LoadConfig("%b\ConfigEx\Private.ini");');
    ProcessMessages;

    Exe('%b\Exec\Config.edt');
    Exe('%b\Exec\%$("Config-Dir");\Load Config.edt');
    IfFileExists("%b\ConfigEx\Private.ini",!'LoadConfig("%b\ConfigEx\Private.ini");');
    IfFileExists("%b\ContribManager\SanitizeMenu.edt",!'Exe("%b\ContribManager\SanitizeMenu.edt");');

    // Reload the last opened project and the List of Projects
    IfFileExists("%b\ConfigEx\Project.ini",>
      !|ReadFile('%b\ConfigEx\Project.ini',0);>
        FindInString('%!0','PROJECT_LIST_DATA_FILE="\(*\)"',-1,-1,1);>
        IfOK(!'LetReg(1,"%#0");',!'LetReg(1,"%b\WinEdt-PrjList.dat");');|,>
      !|LetReg(1,"%b\WinEdt-PrjList.dat");|);
    LetReg(0,@@"%!1"); // Expand it fully!
    IfFileExists("%!0",!'LoadPrjList("",1);',>
      !'IfFileExists("%b\WinEdt.prj",!"DefaultPrj;");');

    PopTagsandRegisters;

    SaveSettings;
    StopWorking;

    Prompt("Your personal configuration has been imported.%\%\>
WARNINGS: %$(`Warn-Count`);%\%\View the LOG file?",1,3,>
      !"Open('%b\Migrate.log',1);");

    Release('Warn-Count');
    Release('Warn-Found');
    Release('Folder');

End;
