; Copyright (C) 2005 Jan Vorel
; http://www.ctuser.net


Declare.s AppPath()
Declare.s InstrRev(xChar1.s)
Declare FlatButton(GadgetHandle.l)

AppPathC.s = AppPath()
#Caption = "The Sims - Setup"
xLong1.l
xLong2.l
xLong3.l
;Dim xChar1$
Dim xByteA1.b(3)
Quit.l

xChar1$ = "Software\Maxis\The Sims"
If RegOpenKeyEx_(-2147483646, @xChar1$, 0, 983103, @xLong3) = 0 
;If RegCreateKeyEx_(-2147483646, @xChar1$, 0, 0, 0, 983103, 0, @xLong3, @xLong2) = 0 
  

  ;"SIMS_MUSIC"="I:\\"
  xChar1$ = "EPInstalled": xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EPDPatch" ;: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP2Installed";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP3Installed";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP3Patch": xChar2$ = "2"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP4Installed": xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP5Installed";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP5Patch";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP6Installed";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "EP7Installed";: xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "HP_INSTALL_COMPLETE": xByteA1(0) = 1
  RegSetValueEx_(xLong3, @xChar1$, 0, 4, @xByteA1(0), 4)
  xChar1$ = "Installed";: xChar2$ = "1"

  xChar1$ = "SIMS_DATA": xChar2$ = AppPathC
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "SIMS_GAME_EDITION": xChar2$ = "239"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))

  xChar1$ = "SIMS_SOUND": xChar2$ = AppPathC + "\SoundData"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "SIMS_SKU": xByteA1(0) = 10
  RegSetValueEx_(xLong3, @xChar1$, 0, 4, @xByteA1(0), 4)
  xChar1$ = "TELEPORT": xChar2$ = "1"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
  xChar1$ = "Version": xChar2$ = "1.2"
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))

  If OpenWindow(#PB_Any, 0, 0, 360, 240, #PB_Window_SystemMenu + #PB_Window_ScreenCentered, #Caption)
    If CreateGadgetList(WindowID())
      If LoadImage(0, "Sims.bmp")
        ImageGadget(2, 0, 0, 360, 148, UseImage(0))
        EndIf
      xLong1 = 155
      TextGadget(10, 10, xLong1, 90, 20, "Language:")
      ComboBoxGadget(11, 110, xLong1, 245, 240)
;      AddGadgetItem(11, -1, "chinese")
;      AddGadgetItem(11, -1, "danish")
;      AddGadgetItem(11, -1, "dutch")
;      AddGadgetItem(11, -1, "english UK")
;      AddGadgetItem(11, -1, "english US")
;      AddGadgetItem(11, -1, "finnish")
;      AddGadgetItem(11, -1, "french")
;      AddGadgetItem(11, -1, "german")
;      AddGadgetItem(11, -1, "italian")
;      AddGadgetItem(11, -1, "japanese")
;      AddGadgetItem(11, -1, "norwegian")
;      AddGadgetItem(11, -1, "polish")
;      AddGadgetItem(11, -1, "portuguese")
;      AddGadgetItem(11, -1, "simplified chinese")
;      AddGadgetItem(11, -1, "spanish")
;      AddGadgetItem(11, -1, "swedish")

      AddGadgetItem(11, -1, "(Default)")
      AddGadgetItem(11, -1, "Danish")
      AddGadgetItem(11, -1, "Dutch")
      AddGadgetItem(11, -1, "Finnish")
      AddGadgetItem(11, -1, "French")
      AddGadgetItem(11, -1, "German")
      AddGadgetItem(11, -1, "Italian")
      AddGadgetItem(11, -1, "Japanese")
      AddGadgetItem(11, -1, "Korean")
      AddGadgetItem(11, -1, "Norwegian")
      AddGadgetItem(11, -1, "Polish")
      AddGadgetItem(11, -1, "Portuguese")
      AddGadgetItem(11, -1, "SimplifiedChinese")
      AddGadgetItem(11, -1, "Spanish")
      AddGadgetItem(11, -1, "Swedish")
      AddGadgetItem(11, -1, "Thai")
      AddGadgetItem(11, -1, "TraditionalChinese")
      AddGadgetItem(11, -1, "UKEnglish")
      AddGadgetItem(11, -1, "USEnglish")

      
      SetGadgetText(11, "(Default)")
      xChar1$ = "SIMS_LANGUAGE": xLong2 = 256: xChar2$ = Space(xLong2)
      If RegQueryValueEx_(xLong3, @xChar1$, 0, xLong4.l, @xChar2$, @xLong2) = 0
        If xLong2 > 0
          SetGadgetText(11, Left(xChar2$, xLong2 - 1))
          EndIf
        EndIf

      xLong1 = xLong1 + 25

      TextGadget(20, 10, xLong1, 90, 20, "Resolution:")
      OptionGadget(21, 110, xLong1, 115, 20, "800x600")
      OptionGadget(22, 235, xLong1, 120, 20, "1024x768")

      xChar1$ = "HighResolution": xLong2 = 256: xChar2$ = Space(xLong2)
      If RegQueryValueEx_(xLong3, @xChar1$, 0, xLong4.l, @xChar2$, @xLong2) = 0
        If xChar2$ = "1"
          SetGadgetState(22, 1)
;          Debug "High"
          Else
          SetGadgetState(21, 1)
;          Debug "Low"
          EndIf
        Else
        SetGadgetState(21, 1)
        EndIf

      xLong1 = xLong1 + 15

      Frame3DGadget(7, -5, xLong1, 370, 60, "")

      xLong1 = xLong1 + 15

      ButtonGadget(8, 182, xLong1, 80, 25, "Run")
      FlatButton(GadgetID(8))
      ButtonGadget(9, 272, xLong1, 80, 25, "Close")
      FlatButton(GadgetID(9))


      Repeat
        EventID.l = WaitWindowEvent()
        Select EventID
          Case #PB_EventGadget
            Select EventGadgetID()
              Case 10 ; List
              Case 15
              Case 16 ; New, Copy
              Case 17 ; Reset
              Case 18 ; Remove
              Case 8
                OnErrorGoto(0)
                Quit = 1
              Case 9
                Quit = 2
              EndSelect
          Case #PB_EventCloseWindow
            Quit = 1
          EndSelect
        Until Quit
      Else
      MessageRequester(#Caption, "Cannot create interface")
      EndIf
    Else
    MessageRequester(#Caption, "Cannot create interface")
    EndIf

  xChar1$ = "HighResolution"
  If GetGadgetState(22)
    xChar2$ = "1"
    Else
    xChar2$ = "0"
    EndIf
  RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))


  xChar1$ = "SIMS_LANGUAGE": xChar2$ = GetGadgetText(11)
  If xChar2$ = "(Default)"
    RegDeleteValue_(xLong3, @xChar1$)
    Else
    RegSetValueEx_(xLong3, @xChar1$, 0, 1, @xChar2$, Len(xChar2$))
    EndIf

  RegCloseKey_(xLong3)
  If Quit = 1
    OnErrorResume()
    xType1.StartupInfo
    xType2.Process_Information
    xType1\cb = 68
    xChar1$ = AppPathC + "\Sims.dat"
    xType1\lpTitle = @xChar1$
    If GetGadgetState(22)
      CreateProcess_(0, Chr(34) + AppPathC + "\Sims.dat" + Chr(34) + " -r1024x768", 0, 0, 0, 0, 0, AppPathC, @xType1, @xType2)
      Else
      CreateProcess_(0, Chr(34) + AppPathC + "\Sims.dat" + Chr(34), 0, 0, 0, 0, 0, AppPathC, @xType1, @xType2)
      EndIf
    OnErrorGoto(0)
    EndIf
  Else
  MessageRequester(#Caption, "Cannot access windows regestry")
  EndIf

End






Procedure.s AppPath()
  xLong1.l
  Result.s

  xLong1 = GetCommandLine_()
  If xLong1 <> 0
    Result = PeekS(xLong1, 65535)
    If Left(Result, 1) = Chr(34) 
      xLong1 = Len(Result) - 2
      If xLong1 = -1
        Result = Mid(Result, 2, xLong1 + 1)
        Else
        Result = Mid(Result, 2, xLong1)
        EndIf
      xLong1 = FindString(Result, Chr(34), 1)
      Else
      xLong1 = FindString(Result, " ", 1)
      EndIf
    If xLong1 <> 0 
      Result = Left(Result, xLong1 - 1)
      EndIf

    Result = InstrRev(Result)
;    Result = "e:\TheSims"
    ProcedureReturn = Result
    EndIf
  EndProcedure

Procedure.s InstrRev(xChar1.s)
  xLong1.l
  xLong2.l

  While 1
    xLong1 = FindString(xChar1, "\", xLong2 + 1)
    If xLong1 = 0 
      Break
      Else
      xLong2 = xLong1
      EndIf
    Wend
  If xLong2 > 0
    ProcedureReturn = Left(xChar1, xLong2 - 1)
    EndIf
  EndProcedure

Procedure FlatButton(GadgetHandle.l)
  SetWindowLong_(GadgetHandle, -16, GetWindowLong_(GadgetHandle, -16) | 32768)
  EndProcedure


; ExecutableFormat=Windows
; EnableXP
; UseIcon=E:\TheSims\# Statter Von sims\simscd.ico
; Executable=E:\TheSims\Sims setup.exe
; DisableDebugger
; EOF