Use DFAllEnt.pkg

// COPYRIGHT (c) 2003-2006 RDC Tools International
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; (See the GPL.txt file in the Help directory) if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Use RdsStartup.pkg
Send Destroy Of (oSplashScreen(Self))  // Remove splash screen
Use cApplication.pkg
Compiler_Desktop_Method_Warnings On

// define workspace constant
Define CURRENT$WORKSPACE For "CrossMerge"

//  Set date attributes as needed
Set_Date_Attribute SysDate4_State To True
Set_Date_Attribute Date4_State    To True
Set_Date_Attribute Epoch_Value    To 30

Send Ignore_Error Of Error_Info_Object 4255 // "Can't load DLL"
Use Help_Ids.inc // Developer should provide this file of help context links.
// For some weird reason we cannot use this in this program.
// If we do the DoShowMapID doesn't work...
//Use cHtmlHelpNew.pkg
Use Std_Help.pkg
Use vsYNCconfirm.pkg   // Better data_loss message. Yes/No/Cancel.
Use CMVdf12StatPnl.pkg // New status panel (included into program code)

Object oApplication Is A cApplication
    Property Integer piUsers 0
    Property String  psSerial ""
    Property String  psName ""
    Property Integer piLicenseType 0
    Property String  psLicenseType "OPEN SOURCE VERSION"
    Property String  psActivationDaysText ""
    Property Handle  phoSDIView 0    // Set by SDI view object
    Property String  psOrgCollectionName ""
    Property String  psDefaultCollection ""
    Property Integer piDaysLeft 0
    Property Integer piUserCode1 0
    Property Integer piUserCode2 0
    Property Integer piActivationDaysLeft 0
    Property Boolean pbActivated False
    Property Handle  phoSynchGrid 0
    Property Handle  phoLfile 0
    Property Handle  phoXmlHttpTransfer   0
    Set psCompany    To "RDC Tools International"
    Set psProduct    To "CrossMerge"
    Set psProgram    To "Engine"
    Set psVersion    To "4.0"
    Set psHelpFile   To "CrossMerge.chm"
    Set peHelpType   To htHtmlHelp
    Set pbPreserveEnvironment To False
    Set pbEnterKeyAsTabKey    To False

    Procedure OnCreate
      Handle hoCmdLine
      Integer iNumArgs iArg
      String sDefaultCollection

      Send DoOpenWorkspace CURRENT$WORKSPACE

      // Allow a 'Collection Name' to be passed on the command line.
      // If the passed name is found in file SncSchem, the default Scheme Name in the system file
      // (SncSys.Default_Scheme) will get changed: (which is necessary for the logic to work, if run un-attended)
      // However, it will get reset when the program is closed.
      Get phoCommandLine              To hoCmdLine
      Get CountOfArgs Of hoCmdLine    To iNumArgs
      Get Argument    Of hoCmdLine 1  To sDefaultCollection
      Set psDefaultCollection         To (Trim(sDefaultCollection))
    End_Procedure // OnCreate

End_Object  // oApplication

Use xxSoftwareKey.pkg  // Modified version of Software Key's copy protection package.
Use Cli.pkg
Use Working.pkg
Use SyncFuncs.pkg
Use ShellExecute.pkg
Use Start_UIExcl.pkg // Do only allow one instance of the program running.

Register_Object oMain
Register_Object oToolbar
Register_Object oClientArea

Use cReindex.pkg
Object oReindex Is A cReindex // Checks if tables needs reindexing.
  Set piCheckFile To 82
End_Object // oName
Use CheckDSN.pkg // Check for necessary ODBC DSN's

Object oMain Is An Panel
  Set Label To "CrossMerge Engine" // Only to make AbortPrgIfRunning work below.

  // Rebar and toolbar properties:
  Property Handle phoFirst              0
  Property Handle phoNext               0
  Property Handle phoLast               0
  Property Handle phoPrevious           0
  Property Handle phoPrompt             0
  Property Handle phoClear              0
  Property Handle phoSave               0
  Property Handle phoDelete             0
  Property Handle phoCut                0
  Property Handle phoCopy               0
  Property Handle phoPaste              0
  Property Integer piVerRebar           0
  Property Integer piVerToolbar         0
  Property Integer piViewSize           0
  Property Integer piVerStatBar         0

  Set Locate_Mode  To Center_On_Screen
  Set Border_Style To Border_Thick

  Object oClientArea Is An AppClientArea
//    Use DD_Debug.dg
    Use Connect.vw

    Use RdcAboutNew.dg
//    Use NagScreen.dg
    Set Client_ScrollBar_State To False
  End_Object // oClientArea

  Use SDIStatusbar.pkg // Status-Bar object.
  Use Tooltip.pkg      // Must be placed here.

  Function Item_Count Returns Integer
  End_Function // Item_Count

  Send AbortPrgIfRunning (Self)

  Procedure Activate_About
    Send Popup Of (oAboutDialog(oClientArea(Self)))
  End_Procedure // Activate_About

  Object oHtmlHelp Is A cHtmlHelpNew
    Set psHelpFile          To "CrossMerge.chm"
  End_Object // oHtmlHelp

  Use cXmlHttpTransfer.pkg
  Object oXmlHttpTransfer Is A cXmlHttpTransfer
    Set peTranslateReceived To xtNoTranslate
    Set peTranslateSent     To xtNoTranslate
    Set phoXmlHttpTransfer  Of ghoApplication To (Self)
  End_Object // oXmlHttpTransfer

  // Old logic:
//  Use RDSPanelSizeLoc.pkg // Auto size and location of program container to the SDI view.
//  Send DoSetPanelSize 0 0 0 (oConnectView(oClientArea(Self))) (oStatusbar(Self))
  // New Logic:
  Use DoReGuiSize.pkg

End_Object // oMain

Send Activate_oConnectView Of (oClientArea(oMain(Self)))

// Moved to LFFile.pkg:
//If (phoLfile(ghoApplication) = 0) Begin
//  If (psDefaultCollection(ghoApplication) = "") ;
//    Send Info_Box "A reboot of the machine is necessary if this is the first time CrossMerge is started after the installation. Else an important component of CrossMerge is missing and the program will be aborted."
//  Abort
//End // If (phoLfile(ghoApplication) = 0) Begin

Procedure DoInitLabel Global
  Set Label Of oMain To ;
    (psProduct(ghoApplication) * psProgram(ghoApplication))
    // * "-" * psLicenseType(ghoApplication) * ;
    //"*** Registered to" * psName(ghoApplication) * "***" * "Serial number" * String(psSerial(ghoApplication)))
End_Procedure // DoInitLabel
Send DoInitLabel

// Do not allow to pass a collection name on the command line,
// if this is _not_ a server license or more.
//If (piLicenseType(ghoApplication) <> CM_Server_Single_CPU And piLicenseType(ghoApplication) <> CM_Server_Multi_CPU And piLicenseType(ghoApplication) <> CM_Server_Eval) Begin       // Constant in Keylib.h
//  If (psDefaultCollection(ghoApplication) <> C_RDCENC) Begin  // Parameter passed from CmBuilder
//    Send DoStartDocument "open" (psProgramPath(phoWorkspace(ghoApplication)) - "\CmBuilder.exe") "" ""
//    Abort
//  End // If (psDefaultCollection(ghoApplication) <> "C_RDCENC") Begin
//  Else Set psDefaultCollection Of ghoApplication To ""
//End // If (piLicenseType(ghoApplication) < 3) Begin

// Server license and started from CmBuilder:
//Else If (psDefaultCollection(ghoApplication) = C_RDCENC) Set psDefaultCollection Of ghoApplication To "" // Parameter passed from CmBuilder
If (Length(psDefaultCollection(ghoApplication)) > 0) Begin
  Open SncSys
  Open SncSchem
  Move (psDefaultCollection(ghoApplication))     To SncSchem.Name
  Find Eq SncSchem.Name
  If (Found) Begin
    Set psOrgCollectionName Of ghoApplication    To (Trim(SncSys.Default_Scheme)) // Save it to be able to reset it before closing program.
    Reread SncSys
      Move (psDefaultCollection(ghoApplication)) To SncSys.Default_Scheme
      Move 1                                     To SncSys.AutoStart
      Saverecord SncSys
    Unlock
  End // If (Found) Begin
End // If (Length(psDefaultCollection(ghoApplication)) > 0) Begin

//Send DoPopupNagScreen Of (oClientArea(oMain(Self))) False
// We must do this here, else the checkboxes doesn't display:
Send OnStartUp        Of (phoSynchGrid(ghoApplication))
Send DoUpdateAbout    Of (oClientArea(oMain(Self)))

Start_UI_Exclusive
//Start_UI
//AB-StoreEnd

//AB/ End_Object    // prj
