// Create or Update WinEdt Links

Requires(20040329); // Requires this build of WinEdt to work properly

// is Power User?
Exe('%B\WinShell\isPowerUser.edt');

// Change this if you want a different Startup Folder, eg.:
// Assign('WinEdt-Start','F:\Your_Documents\TeX');
Assign('WinEdt-Start','');

Assign('WinEdt-Exe','"%B\WinEdt.exe"');
// If there are problems assign the string that your Windows can handle
// Assign('WinEdt-Exe','%~B\WinEdt.exe');

// Write the Log File:
OpenOutput('%b\WinEdt Create Links.log');
// Insert the general information ...
GetDate(9, 'dddd, mmmm d, yyyy "at" hh:nn'); // Date Stamp

WrL(`WinEdt Create Links.log`);
WrL(`Last modified on: `);
WrL(`  %!9%\`);
WrL;
WrL(`Power User: %$('isPowerUser');`);
WrL(`Executable Status: %!0`);
WrL(`Executable File:   <%$('WinEdt-Exe');>`);
WrL(`Startup Folder:    <%$('WinEdt-Start');>`);

// Prepare the Checkbox Dialog

ClearCheckList;

IfStr("%$('isPowerUser');","","=",!"Assign('isPowerUser','1');");

LetReg(0,"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders");

AddCheckList("Current User: ",0,1);
WrL;
WrL(`Current User:`);
WrL;

LetReg(1,'HKEY_CURRENT_USER');
LetReg(2,'');

LetReg(3, "%@('%!1','%!0','%!2Desktop');");
IfFileExists('%!3\','LetReg(5,"0");','LetReg(5,"1");');
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Desktop","%!4","%!5");
WrL('  Desktop (%!4/%!5): "%!3"');

LetReg(3, "%@('%!1','%!0','%!2Programs');");
IfFileExists('%!3\','LetReg(5,"0");','LetReg(5,"1");');
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Start Menu","%!4","%!5");
WrL('  Start Menu (%!4/%!5): "%!3"');

LetReg(3, "%@('%!1','%!0','%!2SendTo');");
IfFileExists('%!3\','LetReg(5,"0");','LetReg(5,"1");');
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Send To","%!4","%!5");
WrL('  Send To (%!4/%!5): "%!3"');

LetReg(3, "%@('%!1','%!0','%!2AppData');");
IfFileExists('%!3\Microsoft\Internet Explorer\Quick Launch\',>
             'LetReg(5,"0");','LetReg(5,"1");');
IfFileExists('%!3\Microsoft\Internet Explorer\Quick Launch\WinEdt 10.lnk',>
             'LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Quick Launch","%!4","%!5");
WrL('  Quick Launch (%!4/%!5): "%!3\Microsoft\Internet Explorer\Quick Launch"');

AddCheckList("Local Machine (All Users): ",0,1);
WrL;
WrL(`Local Machine (All Users):`);
WrL;

LetReg(1,'HKEY_LOCAL_MACHINE');
LetReg(2,'Common ');

LetReg(3, "%@('%!1','%!0','%!2Desktop');");
IfFileExists('%!3\','LetReg(5,"0");','LetReg(5,"1");');
IfStr("%$('isPowerUser');","0","=","LetReg(5,'1');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Desktop","%!4","%!5");
WrL('  Desktop (%!4/%!5): "%!3"');

LetReg(3, "%@('%!1','%!0','%!2Programs');");
IfFileExists('%!3\','LetReg(5,"0");','LetReg(5,"1");');
IfStr("%$('isPowerUser');","0","=","LetReg(5,'1');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"1");','LetReg(4,"0");');
AddCheckList("    Start Menu","%!4","%!5");
WrL('  Start Menu (%!4/%!5): "%!3"');

// Show the Options
  ShowCheckList("WinEdt Links",200,200);
  IfOK('Relax;','CloseOutput;Exit;'); // Continue?

WrL;
WrL;
WrL(`Creating / Removing Links to WinEdt:`);
WrL;

LetRegNum(9,0);

LetReg(0,"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders");

WrL;
WrL(`Current User:`);
WrL;

LetReg(1,'HKEY_CURRENT_USER');
LetReg(2,'');

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2Desktop');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');","",>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Desktop %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Desktop %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Desktop Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Desktop Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2Programs');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');","",>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Start Menu %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Start Menu %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Start Menu Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Start Menu Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2SendTo');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');",'-V',>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Send To %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Send To %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Send To Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Send To Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2AppData');\Microsoft\Internet Explorer\Quick Launch");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');","",>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Quick Launch %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Quick Launch %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Quick Launch Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Quick Launch Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

LetRegNum(9,"%!9+1");

WrL;
WrL(`Local Machine (All Users):`);
WrL;

LetReg(1,'HKEY_LOCAL_MACHINE');
LetReg(2,'Common ');

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2Desktop');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');","",>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Desktop %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Desktop %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Desktop Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Desktop Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

LetRegNum(9,"%!9+1");
LetReg(3, "%@('%!1','%!0','%!2Programs');");
IfFileExists('%!3\WinEdt 10.lnk','LetReg(4,"Update");','LetReg(4,"Create");');
IfChecked(%!9,>
  !`CreateLink("%!3","WinEdt 10","%$('WinEdt-Exe');","",>
               "%$('WinEdt-Start');");>
    IfOK(!'WrL("  Start Menu %!4d: ""%!3\WinEdt 10.lnk""");',>
         !'WrL("  Start Menu %!4 Error: ""%!3\WinEdt 10.lnk""");');>
   `,>
  !`IfFileExists('%!3\WinEdt 10.lnk',>
    !'DeleteFile("%!3\WinEdt 10.lnk");>
      IfOK(!''WrL("  Start Menu Deleted: ""%!3\WinEdt 10.lnk""");'',>
           !''WrL("  Start Menu Delete Error: ""%!3\WinEdt 10.lnk""");'');>
     ');>
   `);

WrL;
CloseOutput;

Release('WinEdt-Exe');
Release('WinEdt-Start');

End;
