const
  bgCount=100;

var
  bgIndex:integer;
  
procedure RefreshPreview;
begin
  xspfrm.beginupdate;
  bgIndex:=((bgIndex-1) mod bgCount)+1;
  
  imgbg.FileName:=WidgetPath+'images\bg'+inttostr(bgIndex)+'.png';
  lblIndex.caption:=inttostr(bgIndex)+'/'+inttostr(bgCount);
  xspfrm.endupdate;
end;

procedure InitDriveList;
begin
  cbbDriveList.items.text:=GetDriveList;
end;

//读取配置
procedure InitIni;
var
  inifn:TIniFile;
begin
  cbbDriveList.ItemIndex:=GetSettingInt('DriveIndex',0);
  edtInterval.text:=GetSetting('RefreshInterval','30');
  bgIndex:=GetSettingInt('bgIndex',1);
  lblIndex.caption:=format('%d/%d',[bgIndex,bgCount]);
  imgbg.FileName:=WidgetPath+'images\bg'+inttostr(bgIndex)+'.png';
  chkUseFSO.checked:=GetSettingInt('UseFSO',1);
end;

//保存配置
procedure SaveIni;
begin
  SetSetting('DriveIndex',cbbDriveList.ItemIndex);
  SetSetting('DriveName',cbbDriveList.text);
  SetSetting('RefreshInterval',edtInterval.text);
  SetSetting('bgIndex',bgIndex);
  SetSettingInt('UseFSO',chkUseFSO.checked);
end;

//--- Widget设置窗口初始化事件，当打开Widget设置窗口时会触发此事件 ---
procedure OnSettingInit;
begin
  Beginupdate;
  InitDriveList;
  InitIni;
  Endupdate;
end;

//--- 按下设置窗口的确定按钮时，触发此事件 ---
//通过设置返回值来改变是否允许确认,当result为False时不关闭设置窗口
function OnSettingClose(iResult);
var
  i:integer;
begin
  result:=true;
  try
    i:=StrToInt(edtInterval.text);
    if i<=0 then raise('');
  except
    showmsg('无效的刷新间隔时间！');
    //edtInterval.SetFocus;
    result:=false;
  end;
  if Result then
    SaveIni;
end;
