Archive: new variables {__YEAR__} {__MONTH__} {__DAY__}


new variables {__YEAR__} {__MONTH__} {__DAY__}
  I made a custom version of MakeNsis.exe 201 to solve a reversioning problem.
I added 3 predefined variables.

!define ${PRODUCT_VERSION} "${__YEAR__}.${__MONTH__}.${__DAY__}" 

>;-> 4.10.02
>
In the script.cpp, 2 modified functions:

void CEXEBuild::set_date_time_predefines()

{
time_t etime;
struct tm * ltime;
char datebuf***91;128***93;;
char timebuf***91;128***93;;
char yearbuf***91;128***93;;
char monthbuf***91;128***93;;
char daybuf***91;128***93;;

time(&etime);
ltime = localtime(&etime);
>#ifdef _WIN32
SYSTEMTIME stime;
stime.wYear = ltime->tm_year+1900;
stime.wMonth = ltime->tm_mon + 1;
stime.wDay = ltime->tm_mday;
stime.wHour= ltime->tm_hour;
stime.wMinute= ltime->tm_min;
stime.wSecond= ltime->tm_sec;
stime.wMilliseconds= 0;
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stime, NULL, datebuf, sizeof(datebuf));
definedlist.add("__DATE__",(char *)datebuf);
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &stime, NULL, timebuf, sizeof(timebuf));
definedlist.add("__TIME__",(char *)timebuf);
GetDateFormat(LOCALE_USER_DEFAULT, 0, &stime, "y", yearbuf, sizeof(yearbuf));
definedlist.add("__YEAR__",(char *)yearbuf);
GetDateFormat(LOCALE_USER_DEFAULT, 0, &stime, "MM", monthbuf, sizeof(monthbuf));
definedlist.add("__MONTH__",(char *)monthbuf);
GetDateFormat(LOCALE_USER_DEFAULT, 0, &stime, "dd", daybuf, sizeof(daybuf));
definedlist.add("__DAY__",(char *)daybuf);
>#else
my_strftime(datebuf, sizeof(datebuf), "%x", ltime);
definedlist.add("__DATE__",(char *)datebuf);
my_strftime(timebuf, sizeof(timebuf), "%X", ltime);
definedlist.add("__TIME__",(char *)timebuf);
my_strftime(yearbuf, sizeof(yearbuf), "%y", ltime);
definedlist.add("__YEAR__",(char *)yearbuf);
my_strftime(monthbuf, sizeof(monthbuf), "%m", ltime);
definedlist.add("__MONTH__",(char *)monthbuf);
my_strftime(daybuf, sizeof(daybuf), "%d", ltime);
definedlist.add("__DAY__",(char *)daybuf);
>#endif
>}

>void CEXEBuild::del_date_time_predefines()
{
definedlist.del("__DATE__");
definedlist.del("__TIME__");
definedlist.del("__YEAR__");
definedlist.del("__MONTH__");
definedlist.del("__DAY__");
}

i would cool if you can include this in the next release


Some times we like "${__YEAR__}.${__MONTH__}.${__DAY__}" but not "${__YEAR__}-${__MONTH__}-${__DAY__}" it's usefull. Hope include in the next release. :)


I think it would be best to make a define switch, or a new command that allows the user to select his own format. That'd also allow to get different times in different places in the script.