theide: SrcUpdater persistant timer, LLOGs

git-svn-id: svn://ultimatepp.org/upp/trunk@3312 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
dolik 2011-03-26 22:42:02 +00:00
parent e4a6dec5fb
commit 586a7c3883
8 changed files with 48 additions and 31 deletions

View file

@ -523,6 +523,7 @@ void AutoSetup()
void AutoSetup() {
InstallWizard iw;
iw.Title("TheIDE - Source management settings");
iw.Block(0);
iw.Block(4);
iw.SetStep(1);

View file

@ -1,8 +1,8 @@
#include "SrcUpdater.h"
//#define IMAGECLASS IdeImg
//#define IMAGEFILE <ide/ide.iml>
//#include <Draw/iml_header.h>
#define IMAGECLASS IdeImg
#define IMAGEFILE <ide/ide.iml>
#include <Draw/iml_header.h>
bool CopyFolder(const char *dst, const char *src, Progress *pi);
bool LoadVarFile(const char *name, VectorMap<String, String>& _var);
@ -15,7 +15,7 @@ bool HasSvn(){
InstallWizard::InstallWizard(){
Title("TheIDE - Initial setting wizard");
Sizeable();
//Icon(IdeImg::Package(), IdeImg::PackageLarge());
Icon(IdeImg::Package(), IdeImg::PackageLarge());
s0.text<<="[ [ [/ Welcome to TheIDE !]&][ &][ [1 This short wizard dialogue will help you to set up everything you need to get a full working Integrated Development Environment. Clicking ][/1 Finish][1 at any time will save the values to your hard disk (using default values for unfilled fields), while ][/1 Cancel][1 leaves this wizard without doing anything.]]";
s1.text<<="[ [ [/ Source code handling methods]&][ &][ [1 There is several ways how to access the U`+`+ source codes. Choose the method that best suits your needs. You can always change the settings later if necessary.]]";
@ -347,6 +347,7 @@ void InstallWizard::Perform(){
DeleteFile(deleted[i]);
}
}
StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml"));
}
void Uninstall(){

View file

@ -2,7 +2,6 @@
using namespace Upp;
LocalSync::LocalSync(const VectorMap<String,int>& changed,const String& localsrc):localsrc(localsrc){
LOG("constructor0");
CtrlLayoutOKCancel(*this, "Synchronize local sources");
list.AddIndex();
list.AddColumn("Action");
@ -89,7 +88,6 @@ void LocalSync::Populate(VectorMap<String,int> changed){
return;
}
for(int i = 0; i < changed.GetCount(); i++){
LOG("populate "<<i);
static Color color[] = {LtBlue, LtRed, Green};
static const char* label[] = {"Show changes", "Show file", "Show file"};
static const char* actions[] = {"Skip\nUpdate", "Skip\nAdd", "Skip\nDelete"};

View file

@ -16,11 +16,13 @@ struct UpdaterConfig{
int method,sync,ignored,period;
String localsrc,globalsrc;
String svnserver,svnuser,svnpass;
Time last;
bool svnreadonly,available;
void Xmlize(XmlIO xml){
xml("Method",method)
("Synchronization",sync)
("CheckPeriod",period)
("LastCheck",last)
("Ignored",ignored)
("LocalSource",localsrc)
("GlobalSource",globalsrc)

View file

@ -1,16 +1,11 @@
#include "SrcUpdater.h"
#define IMAGECLASS IdeImg
#define IMAGEFILE <ide/ide.iml>
#include <Draw/iml_header.h>
#define LLOG(x) //RLOG(x)
#define LDUMP(x) //RDUMP(x)
//bool IsUbuntu(){
// return Sys("lsb_release -si").StartsWith("Ubuntu");
//}
//String GetDebVersion(){
// return Sys("dpkg-query --showformat ${Version} --show theide");
//}
//#define IMAGECLASS IdeImg
//#define IMAGEFILE <ide/ide.iml>
//#include <Draw/iml_header.h>
void LoadUpdaterCfg(){
String cfg=ConfigFile("updates.xml");
@ -20,6 +15,7 @@ void LoadUpdaterCfg(){
UpdaterCfg().method=0;
UpdaterCfg().sync=0;
UpdaterCfg().period=0;
UpdaterCfg().last=Null;
UpdaterCfg().ignored=0;
UpdaterCfg().localsrc=GetHomeDirFile("upp");
UpdaterCfg().svnserver="http://upp-mirror.googlecode.com/svn/trunk/";
@ -40,6 +36,7 @@ String GetSrcVersion(const char* dir,String& error){
ver=ver.Mid(ver.Find('"')+1);
ver=ver.Left(ver.Find('"'));
}
LLOG("GetSrcVersion("<<dir<<") = "<<ver);
return ver;
}
@ -60,10 +57,12 @@ String GetSvnVersion(const String& server,bool verbose,String& error){
int exitcode=p.GetExitCode();
if(exitcode){
error="SVN command 'svn info "+server+"' failed with exit code "+AsString(exitcode)+"&Output:&[l150 "+DeQtf(p.Get());
LDUMP(error);
return "-1";
}
ver=p.Get();
ver=ver.Mid(ver.Find("Revision: ")+10);
LLOG("GetSvnVersion("<<server<<") = "<<IntStr(ScanInt(ver)));
return IntStr(ScanInt(ver));
}
@ -87,11 +86,12 @@ SourceUpdater::SourceUpdater(){
skip<<=THISBACK(Close);
update<<=THISBACK(DoUpdate);
update.SetFocus();
Icon(IdeImg::Package(), IdeImg::PackageLarge());
//Icon(IdeImg::Package(), IdeImg::PackageLarge());
}
bool SourceUpdater::NeedsUpdate(bool verbose){
String where;
LLOG("checking for updates");
switch(UpdaterCfg().method){
case 0:{
//copy in /home
@ -123,6 +123,7 @@ bool SourceUpdater::NeedsUpdate(bool verbose){
}
default: return false;
}
LLOG("NeedsUpdate: local="<<local<<", global="<<global);
if(ScanInt(global)<=UpdaterCfg().ignored) return false;
text<<="[ [ [/ Newer version of U`+`+ sources is available.]&][ &]"
"[ {{5000:5000FNGN@N; [ [1 Curent local version:]]:: [ [1 "+local+"]]:: [ [1 Will update to:]]:: [ [1 "+global+"]]}}][ &&]"
@ -132,7 +133,6 @@ bool SourceUpdater::NeedsUpdate(bool verbose){
void SourceUpdater::CheckUpdates(){
if(UpdaterCfg().method==2) {
RDUMP(UpdaterCfg().sync);
if(UpdaterCfg().sync==1){
global=IDE_VERSION;
CheckLocalSvn();
@ -142,26 +142,28 @@ void SourceUpdater::CheckUpdates(){
return;
}
//else it is fast enough to run without the callback chain
RLOG("running needsupdate");
UpdaterCfg().last=GetUtcTime();
StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml"));
LLOG("running needsupdate");
if(NeedsUpdate(false))
WhenUpdateAvailable();
}
void SourceUpdater::CheckLocalSvn(){
if(pl.IsRunning()) return;
RLOG("check local svn");
LLOG("checking local svn");
pl.Start("svn info "+UpdaterCfg().localsrc);
SetTimeCallback(-50,THISBACK(CheckLocalSvnFinished),1);
}
void SourceUpdater::CheckLocalSvnFinished(){
if(pl.IsRunning()) return;
RLOG("check local svn finished");
LLOG("checking local svn finished");
KillTimeCallback(1);
int exitcode=pl.GetExitCode();
if(exitcode){
error="SVN command 'svn info "+UpdaterCfg().localsrc+"' failed with exit code "+AsString(exitcode)+"&Output:&[l150 "+DeQtf(pl.Get());
RLOG(error);
LDUMP(error);
return;
}
local=pl.Get();
@ -171,25 +173,28 @@ void SourceUpdater::CheckLocalSvnFinished(){
"[ {{5000:5000FNGN@N; [ [1 Curent local version:]]:: [ [1 "+local+"]]:: [ [1 Will update to:]]:: [ [1 "+global+"]]}}][ &&]"
"[1# If you choose to update now, your local sources (directory "+DeQtf(UpdaterCfg().localsrc)+") will be compared to the files in SVN repository ("+DeQtf(UpdaterCfg().svnserver)+"). If you modified the files in your local copy, you will be able to choose appropriate actions for each changed file before writing anything on your hard drive.]";
UpdaterCfg().available=(ScanInt(local)<ScanInt(global));
LLOG("Callback chain finished: local="<<local<<", global="<<global);
UpdaterCfg().last=GetUtcTime();
StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml"));
if(UpdaterCfg().available)
WhenUpdateAvailable();
}
void SourceUpdater::CheckGlobalSvn(){
if(pg.IsRunning()) return;
RLOG("check global svn");
LLOG("checking global svn");
pg.Start("svn info "+UpdaterCfg().svnserver);
SetTimeCallback(-500,THISBACK(CheckGlobalSvnFinished),2);
}
void SourceUpdater::CheckGlobalSvnFinished(){
if(pg.IsRunning()) return;
RLOG("check global svn finished");
LLOG("checking global svn finished");
KillTimeCallback(2);
int exitcode=pg.GetExitCode();
if(exitcode){
error="SVN command 'svn info "+UpdaterCfg().svnserver+"' failed with exit code "+AsString(exitcode)+"&Output:&[l150 "+DeQtf(pg.Get());
RLOG(error);
LLOG(error);
return;
}
global=pg.Get();
@ -201,6 +206,7 @@ void SourceUpdater::CheckGlobalSvnFinished(){
void SourceUpdater::DoUpdate(){
Close();Hide();
LLOG("DoUpdate");
switch(UpdaterCfg().method){
case 0: {
//copy in /home

View file

@ -1,16 +1,18 @@
#include "ide.h"
#define LLOG(x) //RLOG(x)
#define LDUMP(x) //RDUMP(x)
#ifdef PLATFORM_POSIX
GLOBAL_VAR(UpdaterConfig,UpdaterCfg);
void Ide::CheckUpdates(bool verbose){
RLOG("CheckUpdates verbose: "<<verbose);
LLOG("CheckUpdates, verbose="<<verbose);
if(verbose){
RDUMP(su.NeedsUpdate(true));
su.NeedsUpdate(true);
SetBar();
}else{
RLOG("checkupdates");
su.WhenUpdateAvailable=THISBACK(SetBar);
su.CheckUpdates();
}
@ -33,4 +35,9 @@ void Ide::CheckUpdatesManual(){
SetBar();
}
void Ide::SetUpdateTimer(int period){
LLOG("SetUpdateTimer, period="<<period);
PostCallback(THISBACK1(CheckUpdates,false));
SetTimeCallback(-60000*period,THISBACK1(CheckUpdates,false));
}
#endif

View file

@ -905,6 +905,7 @@ public:
void AutoSetup();
void CheckUpdates(bool verbose);
void CheckUpdatesManual();
void SetUpdateTimer(int period);
void Abbreviations();
void BrowseMenu(Bar& menu);

View file

@ -1021,10 +1021,11 @@ void AppMain___()
#ifdef PLATFORM_POSIX
int p=UpdaterCfg().period;
if(!IsNull(p)) {
if(p<=0)
int next=GetUtcTime()-UpdaterCfg().last+abs(p)*60;
if(p <= 0 || next <= 0)
ide.PostCallback(callback1(&ide,&Ide::CheckUpdates,false),0);
if(p!=0)
ide.SetTimeCallback(-60000*abs(p),callback1(&ide,&Ide::CheckUpdates,false));
if(p != 0)
ide.SetTimeCallback(max(0, next),callback1(&ide,&Ide::SetUpdateTimer,abs(p)));
}
#endif