GetTime(hour,min,sec,day,month,year)
Script = SystemPath("ScriptPath") \ SystemPath("ScriptName") & SystemPath("ScriptExt")
RemoveNotifications(Script)


# 실행시 진동.
  Vibrate(100)


# WidgetNewsWeatherUpdater.lnk 삭제
  WidgetUpdaterlnk = "\Windows\시작\WidgetNewsWeatherUpdater.lnk"
  If ( FileExists(WidgetUpdaterlnk)=1 )
     SetFileAttribute( WidgetUpdaterlnk, "hidden", False )
     SetFileAttribute( WidgetUpdaterlnk, "readonly", False )
     SetFileAttribute( WidgetUpdaterlnk, "system", False )
     Delete(WidgetUpdaterlnk)
  EndIf


# 위젯 뉴스, 날씨 자동 업데이트 관련 초기 설정값 지정.
  RegWriteDWord("HKLM", "Software\Samsung\MobileWidget", "NewsAutoUpdate", "0")
  RegWriteDWord("HKLM", "Software\Samsung\MobileWidget", "WeatherAutoUpdate", "0")
  RegWriteDWord("HKLM", "Software\Samsung\MobileWidget", "NewsUpdatePeriod", "8")
  RegWriteDWord("HKLM", "Software\Samsung\MobileWidget", "WeatherUpdatePeriod", "8")


# 위젯 뉴스, 날씨 업데이트.
  WidgetUpdater = "\Windows\WidgetNewsWeatherUpdater.exe"
  Run(WidgetUpdater, "AWU")
  Run(WidgetUpdater, "ANU")
  Sleep(15*1000)
  Kill("WidgetNewsWeatherUpdater.exe")
  RemoveNotifications(WidgetUpdater, "AWU")
  RemoveNotifications(WidgetUpdater, "ANU")


# 위젯 뉴스 타이틀 레지스트리 기록.
  TitleFilePath = ("\MITs Store\temp\widget\")
  If ( Fileexists(TitleFilePath & "newscontent1.txt")=1 )
     FCT = FileModifyTime(TitleFilePath & "newscontent1.txt")
     ScriptUpdate = FormatTime("m월 d일 A h:i", FCT)
     ScriptUpdateL = Length(ScriptUpdate)
     If ( SubStr(ScriptUpdate, 1, 1)=0 )
        ScriptUpdate = SubStr(ScriptUpdate, 2, ScriptUpdateL)
     EndIf
     RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNews", "Update", ScriptUpdate)
     RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNewsPage", "Update", ScriptUpdate)
  Else
     RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNews", "Update", "")
     RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNewsPage", "Update", "")
  EndIf

  For i = 1 to 15
      TitleFile = TitleFilePath & "title" & i & ".txt"
      j = i
      If ( Length(j)=1 )
         j = "0" & j
      Endif
      If ( Fileexists(TitleFile)=1 )
         Title = Part( ReadFile(TitleFile), "^NL^", 1 )
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNews", "Title" & j, i & ". " & Title)
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNewsPage", "PageTitle" & j, i & ". " & Title)
      Else
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNews", "Title" & j, "")
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNewsPage", "PageTitle" & j, "")
      EndIf
  Next
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptNewsPage", "Page", 1)


# 월별 일출/일몰 시간.
  If ( month >= 6 && month <= 8 )
     Sunrise = 5
     Sunset = 20
  ElseIf ( month = 12 || month <= 2 )
     Sunrise = 7
     Sunset = 18
  Else
     Sunrise = 6
     Sunset = 19
  EndIf


# 위젯 날씨 정보 읽어, 레지스트리 기록.
  PM = 0
     If ( hour >= Sunset || hour < Sunrise )
        PM = 1
     Endif

  If ( FCT eq "" )
     ScriptDay = 0
  Else
     ScriptDay = FormatTime("d", TimeStamp()-FCT) - 1
  EndIf

  For i = 0 to 2
      k = i + ScriptDay
      If ( k < 3 )
         MaxTemp[i] = RegRead("HKLM", "Software\Samsung\MobileWidget", "MaxTemp" & k)
         MinTemp[i] = RegRead("HKLM", "Software\Samsung\MobileWidget", "MinTemp" & k)
         WeatherType[i] = RegRead("HKLM", "Software\Samsung\MobileWidget", "WeatherType" & k)

         If ( MaxTemp[i] ne "" && MaxTemp[i] ne "-" )
              MaxTemp[i] = MaxTemp[i] & "℃"
         EndIf
         If ( MinTemp[i] ne "" && MinTemp[i] ne "-" )
              MinTemp[i] = MinTemp[i] & "℃"
         EndIf

         Switch(WeatherType[i])
               case(1)
                   Forecast[i] = "대체로 맑음"
                   ImageFileName[i] = 32 - PM
               case(2, 3)
                   Forecast[i] = "구름 조금"
                   ImageFileName[i] = 30 - PM
               case(4)
                   Forecast[i] = "흐림"
                   ImageFileName[i] = 26
               case(5, 6)
                   Forecast[i] = "흐린 후 조금 맑아짐"
                   ImageFileName[i] = 30 - PM

               case(7, 8, 9, 36, 37, 38, 39, 40)
                   Forecast[i] = "흐리고 소나기"
                   If ( WeatherType[i] < 39 )
                          ImageFileName[i] = 39 + (PM * 6)
                   ElseIf ( WeatherType[i] = 39 )
                          ImageFileName[i] = 35
                   Else
                          ImageFileName[i] = 1
                   EndIf
               case(10, 11, 12, 13, 14)
                   Forecast[i] = "흐리고 비"
                   ImageFileName[i] = 11
               case(15, 16, 17)
                   Forecast[i] = "비가 온 후 갬"
                   ImageFileName[i] = 39 + (PM * 6)

               case(18, 21, 22)
                   Forecast[i] = "흐리고 눈"
                   ImageFileName[i] = 16
               case(19, 20)
                   Forecast[i] = "아침에 눈"
                   ImageFileName[i] = 41 + (PM * 5)
               case(23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35)
                   Forecast[i] = "눈이 온 후 갬"
                   ImageFileName[i] = 41 + (PM * 5)
         EndSwitch

         If (PM = 0)
            DN = "d"
         ElseIf (PM = 1)
            DN = "n"
         EndIf

         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "최고기온", MaxTemp[i])
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "최저기온", MinTemp[i])
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨", Forecast[i])
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨이미지", ImageFileName[i])
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨이미지(dn)", ImageFileName[i] & DN)
      Else
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "최고기온", "")
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "최저기온", "")
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨", "")
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨이미지", "-")
         RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "날씨이미지(dn)", "-")
      EndIf
  Next
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "Day", 0)
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "최고기온", MaxTemp[0])
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "최저기온", MinTemp[0])
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "날씨", Forecast[0])
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "날씨이미지", ImageFileName[0])
      RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "날씨이미지(dn)", ImageFileName[0] & DN)


# 위젯 업데이트 요일, 레지스트리 기록.
  Fw = FormatTime( "w", FCT ) + 1
       WeekArr = Array("일", "월", "화", "수", "목", "금", "토")
       For i = 0 to 2
           k = i + ScriptDay
           If ( k < 3 )
              Fw2 = Fw + i + ScriptDay
              If ( Fw2 > 7 )
                 Fw2 = Fw2 - 7 + ScriptDay
              EndIf
              Week1[i] = WeekArr[Fw2]
              Week2[i] = Week1[i] & "요일"
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(w)", Week1[i])
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일", Week2[i])
           Else
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(w)", "")
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일", "")
           EndIf

           If ( k = 0 )
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(t)", "오늘")
           ElseIf ( k = 1 )
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(t)", "내일")
           ElseIf ( k = 2 )
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(t)", "모레")
           Else
              RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day" & i & "요일(t)", "")
           EndIf
       Next
           RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "요일(w)", Week1[0])
           RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "요일", Week2[0])

           ScriptToday = RegRead("HKLM", "Software\Samsung\MobileWidget\ScriptWeather", "Day0요일(t)")
           RegWriteString("HKLM", "Software\Samsung\MobileWidget\ScriptWeatherToggle", "요일(t)", ScriptToday)


# S2U2 UserWeather - 위젯 날씨 기록.
  S2U2 = "\Program Files\S2U2\s2u2.exe"
  If ( FileExists(S2U2)=1 )
     CurWeather = "C|" & ImageFileName[0] & "| 오늘 : " & MaxTemp[0] & " / " & MinTemp[0] & " / " & Forecast[0]
     UserWeather = RegRead("HKCU", "Software\A_C\S2U2", "UserWeather")

     If ( CurWeather ne UserWeather )
        RegWriteString("HKCU", "Software\A_C\S2U2", "UserWeather", CurWeather)
     EndIf

     ShowWeather = RegRead("HKCU", "Software\A_C\S2U2\", "ShowWeather")
     If ( ShowWeather ne "05" )
        RegWriteBinary("HKCU", "Software\A_C\S2U2\", "ShowWeather", "05")
     EndIf
  EndIf

########################################################################################################

# 추가 실행.
# (S2U2-Widget-Weather-AddRun.mscr 파일이 함께 있을 경우에만 실행됩니다.)

  AddRun = SystemPath("ScriptPath") \ "S2U2-Widget-Weather-AddRun.mscr"
  If ( FileExists(AddRun)=1 )
     Run(AddRun)
  EndIf

########################################################################################################
Exit