{Copyright or © or Copr. :

CNRS - Laboratoire Mouvement & Perception
franck.buloup@univmed.fr

This software is a computer program whose purpose is to highly simplify  
the use of ADwinPro realtime systems when you develop experimental
protocols  on life's sciences area.

This software is governed by the CeCILL  license under French law and
abiding by the rules of distribution of free software.  You can  use, 
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info". 

As a counterpart to the access to the source code and  rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty  and the software's author,  the holder of the
economic rights,  and the successive licensors  have only  limited
liability.

In this respect, the user's attention is drawn to the risks associated
with loading,  using,  modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean  that it is complicated to manipulate,  and  that  also
therefore means  that it is reserved for developers  and  experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or 
data to be ensured and,  more generally, to use and operate it in the 
same conditions as regards security. 

The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.}
unit UGlobal;

interface

uses Windows,Registry,Dialogs,IniFiles,SysUtils,Forms;

var Rep_Actions,Rep_Traitements,Rep_Stimuli,Rep_Fonctions : string;
    Rep_Racine,Rep_Manip,Rep_FichiersInf,ADBasic,SystemType : string;
    Nb_Process,Num_Process,Link_Address : integer;
    Level_Appli, Level_RecupGene, Level_Affiche : string;
    Enreg_Stats,EnReseau,Show_Alpha_Blending : boolean;
		Mode,IPServeur,Port : string;
    Disable_Local_Machine_Navigate : integer;
    Maximized : Boolean;
    topPosition,leftPosition,formWidth,formHeight : integer;    
    executeFormMaximized : Boolean;
    executeFormTopPosition,executeFormLeftPosition,executeFormWidth,executeFormHeight : integer;
    adBasicVersion : integer;
    adBasicIDE, adBasicCompiler : string;          
    cpuID : char;

procedure Readconfig;
procedure ReadLocalMachineNavigate;
procedure InitialLocalMachineNavigate;
procedure saveMainFormPositions(formMaximized : boolean; left, top, width, height : integer);
procedure saveExecuteMainFormPositions(formMaximized : boolean; left, top, width, height : integer);

implementation

procedure Readconfig;
var iniFile : TIniFile;
    //Reg : TRegistry;
begin
    //showmessage('Chemin de recherche de Docometre2.ini : ' +  ExtractFilePath(Application.ExeName) );

    IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\Docometre2.ini');

    Rep_Racine := IniFile.ReadString('Repertoires','RepRacine',GetCurrentDir + '\');
    Rep_Traitements := IniFile.ReadString('Repertoires','RepTraitements',GetCurrentDir + '\Fonctions\Traitements\');
    Rep_Actions := IniFile.ReadString('Repertoires','RepActions',GetCurrentDir + '\Fonctions\Actions\');
    Rep_Fonctions := IniFile.ReadString('Repertoires','RepFonctions',GetCurrentDir + '\Fonctions\');
    Rep_FichiersInf := IniFile.ReadString('Repertoires','RepFichiersInf',GetCurrentDir + '\Fonctions\Inf\');
    Rep_manip := IniFile.ReadString('Repertoires','RepManips','C:\MANIPS2\');
    ADBasic := IniFile.ReadString('Repertoires','RepADBasic','C:\ADwin\ADbasic\');
    adBasicIDE := ADBasic + 'ADbasic.exe';
    adBasicCompiler := ADBasic + 'ADbasicCompiler.exe';

    SystemType := IniFile.ReadString('ADBasic','SystemType','ADWINPRO');
    Nb_Process := IniFile.ReadInteger('ADBasic','NbProcess',1);
    Num_Process := IniFile.ReadInteger('ADBasic','NumProcess',1);
    Link_Address := IniFile.ReadInteger('ADBasic','LinkAddress',336);
    adBasicVersion := IniFile.ReadInteger('ADBasic','adBasicVersion',4);

    Level_Appli :=  IniFile.ReadString('DOCO2','LevelAppli','High');//Process priority
    Level_RecupGene := IniFile.ReadString('DOCO2','LevelRecupGene','TimeCritical');//Thread RecupGene priority
    Level_Affiche := IniFile.ReadString('DOCO2','LevelAfficher','Normal');//Thread Affichage priority
    Enreg_Stats := IniFile.ReadBool('DOCO2','EnregStats',true);
    Show_Alpha_Blending := IniFile.ReadBool('DOCO2','ShowAlphaBlending',true);
    Maximized := IniFile.ReadBool('DOCO2','Maximized',true);
    topPosition := IniFile.ReadInteger('DOCO2','Top_Position',0);
    leftPosition := IniFile.ReadInteger('DOCO2','Left_Position',0);
    formWidth := IniFile.ReadInteger('DOCO2','width',800);
    formHeight := IniFile.ReadInteger('DOCO2','height',600);
    executeFormMaximized := IniFile.ReadBool('DOCO2','executeFormMaximized',true);
    executeFormTopPosition := IniFile.ReadInteger('DOCO2','executeFormTop_Position',0);
    executeFormLeftPosition := IniFile.ReadInteger('DOCO2','executeFormLeft_Position',0);
    executeFormWidth := IniFile.ReadInteger('DOCO2','executeFormWidth',800);
    executeFormHeight := IniFile.ReadInteger('DOCO2','executeFormHeight',600);

    EnReseau := IniFile.ReadBool('DOCO2','EnReseau',false);
    Mode := IniFile.ReadString('DOCO2','Mode','Client');
    IPServeur := IniFile.ReadString('DOCO2','IPServeur','192.168.0.1');
    Port := IniFile.ReadString('DOCO2','Port','1000');

    if((SystemType = 'ADWINPRO') or (SystemType = 'ADWINGOLD'))
    then cpuID := '9';

    if(SystemType = 'ADWINPRO II')
    then cpuID := 'B';

    if(SystemType = 'ADWINPRO II Old Cards')
    then cpuID := 'B';

  if not FileExists(ExtractFilePath(Application.ExeName) + '\Docometre2.ini') then
  begin

    IniFile.writeString('Repertoires','RepRacine',GetCurrentDir + '\');
    IniFile.writeString('Repertoires','RepTraitements',GetCurrentDir + '\Fonctions\Traitements\');
    IniFile.writeString('Repertoires','RepActions',GetCurrentDir + '\Fonctions\Actions\');
    IniFile.writeString('Repertoires','RepFonctions',GetCurrentDir + '\Fonctions\');
    IniFile.writeString('Repertoires','RepFichiersInf',GetCurrentDir + '\Fonctions\Inf\');
    IniFile.writeString('Repertoires','RepManips','C:\MANIPS2\');
    IniFile.writeString('Repertoires','RepADBasic','C:\ADwin\ADbasic\');

    IniFile.writeString('ADBasic','SystemType','ADWINPRO');
    IniFile.WriteInteger('ADBasic','NbProcess',1);
    IniFile.WriteInteger('ADBasic','NumProcess',1);
    IniFile.WriteInteger('ADBasic','LinkAddress',336);
    IniFile.WriteInteger('ADBasic','adBasicVersion',4);

    IniFile.writeString('DOCO2','LevelAppli','High');//Process priority
    IniFile.writeString('DOCO2','LevelRecupGene','TimeCritical');//Thread RecupGene priority
    IniFile.writeString('DOCO2','LevelAfficher','Normal');//Thread Affichage priority
    IniFile.WriteBool('DOCO2','EnregStats',true);
    IniFile.WriteBool('DOCO2','ShowAlphaBlending',true);
    IniFile.WriteBool('DOCO2','Maximized',true);
    IniFile.WriteInteger('DOCO2','Top_Position',0);
    IniFile.WriteInteger('DOCO2','Left_Position',0);
    IniFile.WriteInteger('DOCO2','width',800);
    IniFile.WriteInteger('DOCO2','height',600);
    IniFile.WriteBool('DOCO2','executeFormMaximized',true);
    IniFile.WriteInteger('DOCO2','executeFormTop_Position',0);
    IniFile.WriteInteger('DOCO2','executeFormLeft_Position',0);
    IniFile.WriteInteger('DOCO2','executeFormWidth',800);
    IniFile.WriteInteger('DOCO2','executeFormHeight',600);

    IniFile.WriteBool('DOCO2','EnReseau',false);
    IniFile.writeString('DOCO2','Mode','Client');
    IniFile.writeString('DOCO2','IPServeur','192.168.0.1');
    IniFile.writeString('DOCO2','Port','1000');


  end;

  IniFile.UpdateFile;
  IniFile.Free;
  {
	Reg := TRegistry.create;
	Reg.rootkey := HKEY_LOCAL_MACHINE;
	if Reg.KeyExists('\Software\DOCOMETRE2Reps') then
	begin
		if Reg.OpenKey('\Software\DOCOMETRE2Reps',false) then
		begin
      Rep_Racine := Reg.ReadString('RepRacine');
      Rep_Traitements := Reg.ReadString('RepTraitements');
      Rep_Actions := Reg.ReadString('RepActions');
      Rep_Fonctions := Reg.ReadString('RepFonctions');
      Rep_FichiersInf := Reg.ReadString('RepFichiersInf');
      Rep_manip := Reg.ReadString('RepManips');
      ADBasic := Reg.ReadString('RepADBasic');
      SystemType := Reg.ReadString('SystemType');
      Nb_Process := Reg.ReadInteger('NbProcess');
      Num_Process := Reg.ReadInteger('NumProcess');
      Link_Address := Reg.ReadInteger('LinkAddress');
      Level_Appli :=  Reg.ReadString('LevelAppli');//Process priority
			Level_RecupGene := Reg.ReadString('LevelRecupGene');//Thread RecupGene priority
			Level_Affiche := Reg.ReadString('LevelAfficher');//Thread Affichage priority
			Enreg_Stats := Reg.ReadBool('EnregStats');
			EnReseau := Reg.ReadBool('EnReseau');
      Mode := Reg.ReadString('Mode');
      IPServeur := Reg.ReadString('IPServeur');
			Port := Reg.ReadString('Port');
			try
				Show_Alpha_Blending := Reg.ReadBool('ShowAlphaBlending');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''ShowAlphaBlending'''	then
				 begin
					 Show_Alpha_Blending := true;
					 Reg.WriteBool('ShowAlphaBlending',true);
				 end;
				end;
			end;


      try
				Maximized := Reg.ReadBool('Maximized');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Maximized'''	then
				 begin
					 Maximized := true;
					 Reg.WriteBool('Maximized',true);
				 end;
				end;
			end;

      try
				topPosition := Reg.ReadInteger('Top_Position');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Top_Position'''	then
				 begin
					 topPosition := 0;
					 Reg.WriteInteger('Top_Position',0);
				 end;
				end;
			end;

      try
				leftPosition := Reg.ReadInteger('Left_Position');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Left_Position'''	then
				 begin
					 leftPosition := 0;
					 Reg.WriteInteger('Left_Position',0);
				 end;
				end;
			end;

      try
				formWidth := Reg.ReadInteger('width');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''width'''	then
				 begin
					 formWidth := 400;
					 Reg.WriteInteger('width',formWidth);
				 end;
				end;
			end;

      try
				formHeight := Reg.ReadInteger('height');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''height'''	then
				 begin
					 formHeight := 400;
					 Reg.WriteInteger('height',formHeight);
				 end;
				end;
			end;

      try
				executeFormMaximized := Reg.ReadBool('executeFormMaximized');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Maximized'''	then
				 begin
					 executeFormMaximized := true;
					 Reg.WriteBool('executeFormMaximized',true);
				 end;
				end;
			end;

      try
				executeFormTopPosition := Reg.ReadInteger('executeFormTop_Position');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Top_Position'''	then
				 begin
					 executeFormTopPosition := 0;
					 Reg.WriteInteger('executeFormTop_Position',0);
				 end;
				end;
			end;

      try
				executeFormLeftPosition := Reg.ReadInteger('executeFormLeft_Position');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''Left_Position'''	then
				 begin
					 executeFormLeftPosition := 0;
					 Reg.WriteInteger('executeFormLeft_Position',0);
				 end;
				end;
			end;

      try
				executeFormWidth := Reg.ReadInteger('executeFormWidth');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''width'''	then
				 begin
					 executeFormWidth := 400;
					 Reg.WriteInteger('width',executeFormWidth);
				 end;
				end;
			end;

      try
				executeFormHeight := Reg.ReadInteger('executeFormHeight');
			except
				on E : ERegistryException do
				begin
				 if E.Message = 'Echec à l''obtention des données pour ''height'''	then
				 begin
					 executeFormHeight := 400;
					 Reg.WriteInteger('executeFormHeight',executeFormHeight);
				 end;
				end;
			end;

    end;
  end;
	reg.closeKey;
	reg.free;
  }
	ReadLocalMachineNavigate;
end;

procedure ReadLocalMachineNavigate;
var Reg : TRegistry;
begin
  Reg := TRegistry.create;
	Reg.rootkey := HKEY_CURRENT_USER;
	if Reg.KeyExists('\Software\Microsoft\Internet Explorer\Main')	then
	begin
		if Reg.OpenKey('\Software\Microsoft\Internet Explorer\Main',false) then
		begin
//			try
        if(not Reg.ValueExists('Disable_Local_Machine_Navigate')) then
        begin
          Reg.WriteInteger('Disable_Local_Machine_Navigate',0);
          Disable_Local_Machine_Navigate := -1;
        end;

//				Disable_Local_Machine_Navigate := Reg.ReadInteger('Disable_Local_Machine_Navigate');
//			except
//				on ERegistryException do
//        begin
//          Disable_Local_Machine_Navigate := -1;
//          Reg.WriteInteger('Disable_Local_Machine_Navigate',0);
//        end;
//			end;
		end;
	end;
	reg.closeKey;
	reg.free;
end;

procedure InitialLocalMachineNavigate; 
var Reg : TRegistry;
begin
  Reg := TRegistry.create;
	Reg.rootkey := HKEY_CURRENT_USER;
	if Reg.KeyExists('\Software\Microsoft\Internet Explorer\Main')	then
	begin
		if Reg.OpenKey('\Software\Microsoft\Internet Explorer\Main',false) then
		begin
			if Disable_Local_Machine_Navigate = -1
			then Reg.DeleteValue('Disable_Local_Machine_Navigate')
			else Reg.WriteInteger('Disable_Local_Machine_Navigate',Disable_Local_Machine_Navigate);
		end;
	end;
	reg.closeKey;
	reg.free;
end;

procedure saveMainFormPositions(formMaximized : boolean; left, top, width, height : integer);
var iniFile : TIniFile;
    //Reg : TRegistry;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\Docometre2.ini');
  IniFile.WriteBool('DOCO2','Maximized',formMaximized);
  if(not formMaximized) then
  begin
    IniFile.WriteInteger('DOCO2','Top_Position',top);
    IniFile.WriteInteger('DOCO2','Left_Position',left);
    IniFile.WriteInteger('DOCO2','width',width);
    IniFile.WriteInteger('DOCO2','height',height);
  end;
  iniFile.UpdateFile;
  IniFile.free;
  {
  Reg := TRegistry.create;
	Reg.rootkey := HKEY_LOCAL_MACHINE;
	if Reg.KeyExists('\Software\DOCOMETRE2Reps') then
	begin
		if Reg.OpenKey('\Software\DOCOMETRE2Reps',false) then
		begin
      Reg.WriteBool('Maximized',formMaximized);
      if(not formMaximized) then
      begin
        Reg.WriteInteger('Top_Position',top);
        Reg.WriteInteger('Left_Position',left);
        Reg.WriteInteger('width',width);
        Reg.WriteInteger('height',height);
      end;
    end;
  end;
	reg.closeKey;
	reg.free;           }
end;


procedure saveExecuteMainFormPositions(formMaximized : boolean; left, top, width, height : integer);
var iniFile : TIniFile;
    //Reg : TRegistry;
begin
  IniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\Docometre2.ini');
  IniFile.WriteBool('DOCO2','executeFormMaximized',formMaximized);
  if(not formMaximized) then
  begin
    IniFile.WriteInteger('DOCO2','executeFormTop_Position',top);
    IniFile.WriteInteger('DOCO2','executeFormLeft_Position',left);
    IniFile.WriteInteger('DOCO2','executeFormWidth',width);
    IniFile.WriteInteger('DOCO2','executeFormHeight',height);
  end;
  iniFile.UpdateFile;
  IniFile.free;
  {
  Reg := TRegistry.create;
	Reg.rootkey := HKEY_LOCAL_MACHINE;
	if Reg.KeyExists('\Software\DOCOMETRE2Reps') then
	begin
		if Reg.OpenKey('\Software\DOCOMETRE2Reps',false) then
		begin
      Reg.WriteBool('executeFormMaximized',formMaximized);
      if(not formMaximized) then
      begin
        Reg.WriteInteger('executeFormTop_Position',top);
        Reg.WriteInteger('executeFormLeft_Position',left);
        Reg.WriteInteger('executeFormWidth',width);
        Reg.WriteInteger('executeFormHeight',height);
      end;
    end;
  end;
	reg.closeKey;
	reg.free;         }
end;

end.


