2
2
#include <cstdlib> //For random numbers
9
#include <wx/filename.h>
12
#include <wx/msgdlg.h>
14
#include <cbproject.h>
6
#include <wx/dynarray.h>
10
#include <wx/filename.h>
13
#include <wx/msgdlg.h>
15
#include <cbproject.h>
15
16
#include "globals.h"
17
#include <projectbuildtarget.h>
18
#include <projectmanager.h>
18
#include <projectbuildtarget.h>
19
#include <projectmanager.h>
19
20
#include <tinyxml/tinyxml.h>
22
23
#include "projectloader_hooks.h"
24
#include "AutoVersioning.h"
25
#include "avSvnRevision.h"
26
#include "avVersionEditorDlg.h"
25
#include "AutoVersioning.h"
26
#include "avSvnRevision.h"
27
#include "avVersionEditorDlg.h"
27
28
#include "avChangesDlg.h"
28
29
#include "avHeader.h"
32
const int idMenuAutoVersioning = wxNewId();
33
const int idMenuCommitChanges = wxNewId();
34
const int idMenuChangesLog = wxNewId();
37
KILLERBOT : TODO : is this really needed ??
38
EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
39
EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
44
BEGIN_EVENT_TABLE(AutoVersioning,wxEvtHandler)
45
EVT_TIMER(-1, AutoVersioning::OnTimerVerify)
47
EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
48
EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
49
EVT_UPDATE_UI(idMenuChangesLog, AutoVersioning::OnUpdateUI)
50
EVT_MENU(idMenuAutoVersioning, AutoVersioning::OnMenuAutoVersioning)
51
EVT_MENU(idMenuCommitChanges, AutoVersioning::OnMenuCommitChanges)
52
EVT_MENU(idMenuChangesLog, AutoVersioning::OnMenuChangesLog)
58
PluginRegistrant<AutoVersioning> reg(_T("AutoVersioning"));
61
//{Constructor and Destructor
62
AutoVersioning::AutoVersioning()
33
const int idMenuAutoVersioning = wxNewId();
34
const int idMenuCommitChanges = wxNewId();
35
const int idMenuChangesLog = wxNewId();
38
KILLERBOT : TODO : is this really needed ??
39
EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
40
EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
45
BEGIN_EVENT_TABLE(AutoVersioning,wxEvtHandler)
46
EVT_TIMER(-1, AutoVersioning::OnTimerVerify)
48
EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
49
EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
50
EVT_UPDATE_UI(idMenuChangesLog, AutoVersioning::OnUpdateUI)
51
EVT_MENU(idMenuAutoVersioning, AutoVersioning::OnMenuAutoVersioning)
52
EVT_MENU(idMenuCommitChanges, AutoVersioning::OnMenuCommitChanges)
53
EVT_MENU(idMenuChangesLog, AutoVersioning::OnMenuChangesLog)
59
PluginRegistrant<AutoVersioning> reg(_T("AutoVersioning"));
62
//{Constructor and Destructor
63
AutoVersioning::AutoVersioning()
64
65
// hook to project loading procedure
65
66
ProjectLoaderHooks::HookFunctorBase* AutoVerHook =
66
67
new ProjectLoaderHooks::HookFunctor<AutoVersioning>(this, &AutoVersioning::OnProjectLoadingHook);
67
68
m_AutoVerHookId = ProjectLoaderHooks::RegisterHook(AutoVerHook);
68
m_IsCurrentProjectVersioned = false;
69
69
m_Modified = false;
71
} // end of constructor
73
AutoVersioning::~AutoVersioning()
71
} // end of constructor
73
AutoVersioning::~AutoVersioning()
75
75
ProjectLoaderHooks::UnregisterHook(m_AutoVerHookId, true);
76
} // end of destructor
80
void AutoVersioning::OnAttach()
84
wxMessageBox(_("Error loading AutoVersioning Plugin!"),_("Error"),wxICON_ERROR );
87
m_timerStatus = new wxTimer(this,30000);
88
m_timerStatus->Start(1000);
90
//Register functions to events
76
} // end of destructor
80
void AutoVersioning::OnAttach()
84
wxMessageBox(_("Error loading AutoVersioning Plugin!"),_("Error"),wxICON_ERROR );
87
m_timerStatus = new wxTimer(this,30000);
88
m_timerStatus->Start(1000);
90
//Register functions to events
91
91
// register event sink
92
92
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_ACTIVATE, new cbEventFunctor<AutoVersioning, CodeBlocksEvent>(this, &AutoVersioning::OnProjectActivated));
93
93
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_CLOSE, new cbEventFunctor<AutoVersioning, CodeBlocksEvent>(this, &AutoVersioning::OnProjectClosed));
94
Manager::Get()->RegisterEventSink(cbEVT_COMPILER_STARTED, new cbEventFunctor<AutoVersioning, CodeBlocksEvent>(this, &AutoVersioning::OnCompilerStarted));
94
Manager::Get()->RegisterEventSink(cbEVT_COMPILER_STARTED, new cbEventFunctor<AutoVersioning, CodeBlocksEvent>(this, &AutoVersioning::OnCompilerStarted));
95
95
Manager::Get()->RegisterEventSink(cbEVT_COMPILER_FINISHED, new cbEventFunctor<AutoVersioning, CodeBlocksEvent>(this, &AutoVersioning::OnCompilerFinished));
96
//NOTE : all those registered through EventSink don't need to call event.skip() [that is only needed when going through wx]
99
void AutoVersioning::OnRelease(bool appShutDown)
101
if (m_timerStatus->IsRunning())
103
m_timerStatus->Stop();
105
delete m_timerStatus;
109
void AutoVersioning::BuildMenu(wxMenuBar* menuBar)
111
int idProject = menuBar->FindMenu(_("Project"));
112
if (idProject != wxNOT_FOUND)
114
wxMenu* project = menuBar->GetMenu(idProject);
115
project->AppendSeparator();
116
project->Append(idMenuAutoVersioning, _("Autoversioning"), _("Manage your project version"));
117
project->Append(idMenuCommitChanges, _("Increment Version"), _("Increments and update the version info"));
118
project->Append(idMenuChangesLog, _("Changes Log"), _("View and edit the actual changes"));
96
//NOTE : all those registered through EventSink don't need to call event.skip() [that is only needed when going through wx]
99
void AutoVersioning::OnRelease(bool appShutDown)
101
if (m_timerStatus->IsRunning())
103
m_timerStatus->Stop();
105
delete m_timerStatus;
109
void AutoVersioning::BuildMenu(wxMenuBar* menuBar)
111
int idProject = menuBar->FindMenu(_("&Project"));
112
if (idProject != wxNOT_FOUND)
114
wxMenu* project = menuBar->GetMenu(idProject);
115
project->AppendSeparator();
116
project->Append(idMenuAutoVersioning, _("Autoversioning"), _("Manage your project version"));
117
project->Append(idMenuCommitChanges, _("Increment version"), _("Increments and update the version info"));
118
project->Append(idMenuChangesLog, _("Changes log"), _("View and edit the actual changes"));
124
124
void AutoVersioning::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading)
128
// TODO (KILLERBOT) : should we have default values, in case something would be missing ?
129
// OPTI : we could choose not to write out default values in the xml --> smaller cbp
131
m_IsCurrentProjectVersioned = false; // default not active unless we find xml for it
132
const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning");
135
m_IsCurrentProjectVersioned = true;
136
TiXmlHandle Handle(const_cast<TiXmlElement*>(Node));
137
if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement())
140
if(pElem->QueryIntAttribute("minor_max", &Help) == TIXML_SUCCESS)
142
Config.Scheme.MinorMax = static_cast<long>(Help);
144
if(pElem->QueryIntAttribute("build_max", &Help) == TIXML_SUCCESS)
146
Config.Scheme.BuildMax = static_cast<long>(Help);
148
if(pElem->QueryIntAttribute("rev_max", &Help) == TIXML_SUCCESS)
150
Config.Scheme.RevisionMax = static_cast<long>(Help);
152
if(pElem->QueryIntAttribute("rev_rand_max", &Help) == TIXML_SUCCESS)
154
Config.Scheme.RevisionRandMax = static_cast<long>(Help);
156
if(pElem->QueryIntAttribute("build_times_to_increment_minor", &Help) == TIXML_SUCCESS)
158
Config.Scheme.BuildTimesToIncrementMinor = static_cast<long>(Help);
161
if(const TiXmlElement* pElem = Handle.FirstChildElement("Settings").ToElement())
163
Config.Settings.Language = pElem->Attribute("language");
164
Config.Settings.SvnDirectory = pElem->Attribute("svn_directory");
165
Config.Settings.HeaderPath = pElem->Attribute("header_path");
168
if(pElem->QueryIntAttribute("autoincrement", &Help) == TIXML_SUCCESS)
170
Config.Settings.Autoincrement = Help?true:false;
172
if(pElem->QueryIntAttribute("date_declarations", &Help) == TIXML_SUCCESS)
174
Config.Settings.DateDeclarations = Help?true:false;
176
if(pElem->QueryIntAttribute("do_auto_increment", &Help) == TIXML_SUCCESS)
178
Config.Settings.DoAutoIncrement = Help?true:false;
180
if(pElem->QueryIntAttribute("ask_to_increment", &Help) == TIXML_SUCCESS)
182
Config.Settings.AskToIncrement = Help?true:false;
184
if(pElem->QueryIntAttribute("svn", &Help) == TIXML_SUCCESS)
186
Config.Settings.Svn = Help?true:false;
189
if(const TiXmlElement* pElem = Handle.FirstChildElement("Changes_Log").ToElement())
191
Config.ChangesLog.AppTitle = pElem->Attribute("app_title");
192
Config.ChangesLog.ChangesLogPath = pElem->Attribute("changeslog_path");
195
if(pElem->QueryIntAttribute("show_changes_editor", &Help) == TIXML_SUCCESS)
197
Config.ChangesLog.ShowChangesEditor = Help?true:false;
201
avVersionState VersionState;
202
m_versionHeaderPath = FileNormalize(cbC2U(Config.Settings.HeaderPath.c_str()),project->GetBasePath());
204
avHeader VersionHeader;
128
// TODO (KILLERBOT) : should we have default values, in case something would be missing ?
129
// OPTI : we could choose not to write out default values in the xml --> smaller cbp
131
m_IsVersioned[project] = false; // default not active unless we find xml for it
132
const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning");
135
m_IsVersioned[project] = true;
136
TiXmlHandle Handle(const_cast<TiXmlElement*>(Node));
137
if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement())
140
if(pElem->QueryIntAttribute("minor_max", &Help) == TIXML_SUCCESS)
142
Config.Scheme.MinorMax = static_cast<long>(Help);
144
if(pElem->QueryIntAttribute("build_max", &Help) == TIXML_SUCCESS)
146
Config.Scheme.BuildMax = static_cast<long>(Help);
148
if(pElem->QueryIntAttribute("rev_max", &Help) == TIXML_SUCCESS)
150
Config.Scheme.RevisionMax = static_cast<long>(Help);
152
if(pElem->QueryIntAttribute("rev_rand_max", &Help) == TIXML_SUCCESS)
154
Config.Scheme.RevisionRandMax = static_cast<long>(Help);
156
if(pElem->QueryIntAttribute("build_times_to_increment_minor", &Help) == TIXML_SUCCESS)
158
Config.Scheme.BuildTimesToIncrementMinor = static_cast<long>(Help);
161
if(const TiXmlElement* pElem = Handle.FirstChildElement("Settings").ToElement())
163
Config.Settings.Language = pElem->Attribute("language");
164
Config.Settings.SvnDirectory = pElem->Attribute("svn_directory");
165
Config.Settings.HeaderPath = pElem->Attribute("header_path");
168
if(pElem->QueryIntAttribute("autoincrement", &Help) == TIXML_SUCCESS)
170
Config.Settings.Autoincrement = Help?true:false;
172
if(pElem->QueryIntAttribute("date_declarations", &Help) == TIXML_SUCCESS)
174
Config.Settings.DateDeclarations = Help?true:false;
176
if(pElem->QueryIntAttribute("do_auto_increment", &Help) == TIXML_SUCCESS)
178
Config.Settings.DoAutoIncrement = Help?true:false;
180
if(pElem->QueryIntAttribute("ask_to_increment", &Help) == TIXML_SUCCESS)
182
Config.Settings.AskToIncrement = Help?true:false;
184
if(pElem->QueryIntAttribute("svn", &Help) == TIXML_SUCCESS)
186
Config.Settings.Svn = Help?true:false;
189
if(const TiXmlElement* pElem = Handle.FirstChildElement("Code").ToElement())
191
Config.Code.HeaderGuard = pElem->Attribute("header_guard");
192
Config.Code.NameSpace = pElem->Attribute("namespace");
193
Config.Code.Prefix = pElem->Attribute("prefix");
195
if(const TiXmlElement* pElem = Handle.FirstChildElement("Changes_Log").ToElement())
197
Config.ChangesLog.AppTitle = pElem->Attribute("app_title");
198
Config.ChangesLog.ChangesLogPath = pElem->Attribute("changeslog_path");
201
if(pElem->QueryIntAttribute("show_changes_editor", &Help) == TIXML_SUCCESS)
203
Config.ChangesLog.ShowChangesEditor = Help?true:false;
207
avVersionState VersionState;
208
m_versionHeaderPath = FileNormalize(cbC2U(Config.Settings.HeaderPath.c_str()),project->GetBasePath());
210
avHeader VersionHeader;
205
211
if(VersionHeader.LoadFile(m_versionHeaderPath))
207
213
VersionState.Values.Major = VersionHeader.GetValue(_("MAJOR"));
211
217
VersionState.Values.BuildCount = VersionHeader.GetValue(_("BUILDS_COUNT"));
212
218
VersionState.Status.SoftwareStatus = cbU2C(VersionHeader.GetString(_("STATUS")));
213
219
VersionState.Status.Abbreviation = cbU2C(VersionHeader.GetString(_("STATUS_SHORT")));
214
VersionState.BuildHistory = VersionHeader.GetValue(_("BUILD_HISTORY"));
216
m_ProjectMap[project] = Config;
217
m_ProjectMapVersionState[project] = VersionState;
222
// Hook called when saving project file.
224
// since rev4332, the project keeps a copy of the <Extensions> element
225
// and re-uses it when saving the project (so to avoid losing entries in it
226
// if plugins that use that element are not loaded atm).
227
// so, instead of blindly inserting the element, we must first check it's
228
// not already there (and if it is, clear its contents)
229
if(m_IsCurrentProjectVersioned)
231
TiXmlElement* node = elem->FirstChildElement("AutoVersioning");
234
node = elem->InsertEndChild(TiXmlElement("AutoVersioning"))->ToElement();
238
//Used this instead of GetConfig() since if the project is not activated
239
//before saving, then the m_Project is not updated.
240
//This will happen when having multiple projects opened.
241
avConfig NewConfig = m_ProjectMap[project];
243
TiXmlElement Scheme("Scheme");
244
Scheme.SetAttribute("minor_max", NewConfig.Scheme.MinorMax);
245
Scheme.SetAttribute("build_max", NewConfig.Scheme.BuildMax);
246
Scheme.SetAttribute("rev_max", NewConfig.Scheme.RevisionMax);
247
Scheme.SetAttribute("rev_rand_max", NewConfig.Scheme.RevisionRandMax);
248
Scheme.SetAttribute("build_times_to_increment_minor", NewConfig.Scheme.BuildTimesToIncrementMinor);
249
node->InsertEndChild(Scheme);
250
TiXmlElement Settings("Settings");
251
Settings.SetAttribute("autoincrement", NewConfig.Settings.Autoincrement);
252
Settings.SetAttribute("date_declarations", NewConfig.Settings.DateDeclarations);
253
Settings.SetAttribute("do_auto_increment", NewConfig.Settings.DoAutoIncrement);
254
Settings.SetAttribute("ask_to_increment", NewConfig.Settings.AskToIncrement);
255
Settings.SetAttribute("language", NewConfig.Settings.Language.c_str());
256
Settings.SetAttribute("svn", NewConfig.Settings.Svn);
257
Settings.SetAttribute("svn_directory", NewConfig.Settings.SvnDirectory.c_str());
258
Settings.SetAttribute("header_path", NewConfig.Settings.HeaderPath.c_str());
259
node->InsertEndChild(Settings);
260
TiXmlElement ChangesLog("Changes_Log");
261
ChangesLog.SetAttribute("show_changes_editor", NewConfig.ChangesLog.ShowChangesEditor);
262
ChangesLog.SetAttribute("app_title", NewConfig.ChangesLog.AppTitle.c_str());
263
ChangesLog.SetAttribute("changeslog_path", NewConfig.ChangesLog.ChangesLogPath.c_str());
264
node->InsertEndChild(ChangesLog);
266
// TODO (KILLERBOT) : what if we decide to not version anymore : how to remove ??
220
VersionState.BuildHistory = VersionHeader.GetValue(_("BUILD_HISTORY"));
222
m_ProjectMap[project] = Config;
223
m_ProjectMapVersionState[project] = VersionState;
227
// Hook called when saving project file.
229
// since rev4332, the project keeps a copy of the <Extensions> element
230
// and re-uses it when saving the project (so to avoid losing entries in it
231
// if plugins that use that element are not loaded atm).
232
// so, instead of blindly inserting the element, we must first check it's
233
// not already there (and if it is, clear its contents)
234
if(m_IsVersioned[project])
236
TiXmlElement* node = elem->FirstChildElement("AutoVersioning");
239
node = elem->InsertEndChild(TiXmlElement("AutoVersioning"))->ToElement();
243
//Used this instead of GetConfig() since if the project is not activated
244
//before saving, then the m_Project is not updated.
245
//This will happen when having multiple projects opened.
246
avConfig NewConfig = m_ProjectMap[project];
248
TiXmlElement Scheme("Scheme");
249
Scheme.SetAttribute("minor_max", NewConfig.Scheme.MinorMax);
250
Scheme.SetAttribute("build_max", NewConfig.Scheme.BuildMax);
251
Scheme.SetAttribute("rev_max", NewConfig.Scheme.RevisionMax);
252
Scheme.SetAttribute("rev_rand_max", NewConfig.Scheme.RevisionRandMax);
253
Scheme.SetAttribute("build_times_to_increment_minor", NewConfig.Scheme.BuildTimesToIncrementMinor);
254
node->InsertEndChild(Scheme);
255
TiXmlElement Settings("Settings");
256
Settings.SetAttribute("autoincrement", NewConfig.Settings.Autoincrement);
257
Settings.SetAttribute("date_declarations", NewConfig.Settings.DateDeclarations);
258
Settings.SetAttribute("do_auto_increment", NewConfig.Settings.DoAutoIncrement);
259
Settings.SetAttribute("ask_to_increment", NewConfig.Settings.AskToIncrement);
260
Settings.SetAttribute("language", NewConfig.Settings.Language.c_str());
261
Settings.SetAttribute("svn", NewConfig.Settings.Svn);
262
Settings.SetAttribute("svn_directory", NewConfig.Settings.SvnDirectory.c_str());
263
Settings.SetAttribute("header_path", NewConfig.Settings.HeaderPath.c_str());
264
node->InsertEndChild(Settings);
265
TiXmlElement ChangesLog("Changes_Log");
266
ChangesLog.SetAttribute("show_changes_editor", NewConfig.ChangesLog.ShowChangesEditor);
267
ChangesLog.SetAttribute("app_title", NewConfig.ChangesLog.AppTitle.c_str());
268
ChangesLog.SetAttribute("changeslog_path", NewConfig.ChangesLog.ChangesLogPath.c_str());
269
node->InsertEndChild(ChangesLog);
270
TiXmlElement Code("Code");
271
Code.SetAttribute("header_guard", NewConfig.Code.HeaderGuard.c_str());
272
Code.SetAttribute("namespace", NewConfig.Code.NameSpace.c_str());
273
Code.SetAttribute("prefix", NewConfig.Code.Prefix.c_str());
274
node->InsertEndChild(Code);
276
// TODO (KILLERBOT) : what if we decide to not version anymore : how to remove ??
268
278
}// OnProjectLoadingHook
270
280
void AutoVersioning::OnProjectActivated(CodeBlocksEvent& event)
274
// switch to the settings of the now activated project [I assume it has already been loaded before this triggers]
275
m_Project = event.GetProject();
284
// switch to the settings of the now activated project [I assume it has already been loaded before this triggers]
285
m_Project = event.GetProject();
277
287
}// OnProjectActivated
279
289
void AutoVersioning::OnProjectClosed(CodeBlocksEvent& event)
283
m_ProjectMap.erase(event.GetProject());
284
m_ProjectMapVersionState.erase(event.GetProject());
285
if(m_Project == event.GetProject())
286
{ // should always be the case (??? we hope ??)
293
m_ProjectMap.erase(event.GetProject());
294
m_ProjectMapVersionState.erase(event.GetProject());
295
m_IsVersioned.erase(event.GetProject());
296
if(m_Project == event.GetProject())
297
{ // should always be the case (??? we hope ??)
290
301
}// OnProjectClosed
292
303
// KILLERBOT : TODO : only do this when active (!!!!!!!!!!!), ie when autoversioning this project
293
304
// BIG QUESTION : what will happen on rebuild workspace, will every project being build
294
// be activated and each has the compilerstarted/Finished ?????
295
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
297
if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
301
const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
302
const bool askToIncrement = GetConfig().Settings.AskToIncrement;
303
if (doAutoIncrement && askToIncrement)
305
if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
310
else if(doAutoIncrement)
316
} // end of OnCompilerStarted
318
void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
320
if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
322
++(GetVersionState().Values.BuildCount);
324
} // end of OnCompilerFinished
326
void AutoVersioning::OnTimerVerify(wxTimerEvent& event)
328
if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
332
for (int i=0; i < m_Project->GetFilesCount(); ++i)
334
const ProjectFile* file = m_Project->GetFile(i);
335
if (file->GetFileState() == fvsModified)
343
} // end of OnTimerVerify
345
void AutoVersioning::OnMenuAutoVersioning(wxCommandEvent&)
351
if (m_IsCurrentProjectVersioned)
353
SetVersionAndSettings(*m_Project, true);
354
UpdateVersionHeader();
358
if (wxMessageBox(_("Configure the project \"") + m_Project->GetTitle() + _("\" for Autoversioning?"),_("Autoversioning"),wxYES_NO) == wxYES)
361
m_IsCurrentProjectVersioned = true;
362
// just becasue we activated the project becomes modified
363
m_Project->SetModified();
365
SetVersionAndSettings(*m_Project);
366
UpdateVersionHeader();
368
for (int i = 1; i < m_Project->GetBuildTargetsCount(); ++i)
370
m_Project->AddFile(i, m_versionHeaderPath, true, true, 0);
372
wxMessageBox(_("Project configured!"));
378
cbMessageBox(_("No active project!"), _("Error"), wxICON_ERROR | wxOK);
383
void AutoVersioning::OnMenuCommitChanges(wxCommandEvent&)
385
if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
305
// be activated and each has the compilerstarted/Finished ?????
306
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
308
if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])
312
const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
313
const bool askToIncrement = GetConfig().Settings.AskToIncrement;
314
if (doAutoIncrement && askToIncrement)
316
if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
321
else if(doAutoIncrement)
327
} // end of OnCompilerStarted
329
void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
331
if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])
333
++(GetVersionState().Values.BuildCount);
335
} // end of OnCompilerFinished
337
void AutoVersioning::OnTimerVerify(wxTimerEvent& event)
339
if (m_Project && IsAttached() && m_IsVersioned[m_Project])
343
for (int i=0; i < m_Project->GetFilesCount(); ++i)
345
const ProjectFile* file = m_Project->GetFile(i);
346
if (file->GetFileState() == fvsModified)
354
} // end of OnTimerVerify
356
void AutoVersioning::OnMenuAutoVersioning(wxCommandEvent&)
362
if (m_IsVersioned[m_Project])
364
SetVersionAndSettings(*m_Project, true);
365
UpdateVersionHeader();
369
if (wxMessageBox(_("Configure the project \"") + m_Project->GetTitle() + _("\" for Autoversioning?"),_("Autoversioning"),wxYES_NO) == wxYES)
371
if(wxFileExists(m_Project->GetBasePath() + _T("version.h")))
374
_T("The header version.h already exist on your projects path. "
375
"The content will be overwritten by the the version info generated code."
376
"\n\nYou can change the default version.h file on the \"Settings\" Tab."
379
wxICON_EXCLAMATION | wxOK
384
m_IsVersioned[m_Project] = true;
385
// just becasue we activated the project becomes modified
386
m_Project->SetModified();
388
SetVersionAndSettings(*m_Project);
389
UpdateVersionHeader();
391
wxArrayInt target_array;
392
for (int i = 0; i < m_Project->GetBuildTargetsCount(); ++i)
396
Manager::Get()->GetProjectManager()->AddFileToProject(m_versionHeaderPath, m_Project, target_array);
397
Manager::Get()->GetProjectManager()->RebuildTree();
398
wxMessageBox(_("Project configured!"));
404
cbMessageBox(_("No active project!"), _("Error"), wxICON_ERROR | wxOK);
409
void AutoVersioning::OnMenuCommitChanges(wxCommandEvent&)
411
if (m_Project && IsAttached() && m_IsVersioned[m_Project])
394
void AutoVersioning::OnMenuChangesLog(wxCommandEvent&)
399
void AutoVersioning::OnUpdateUI(wxUpdateUIEvent& event)
405
if(event.GetId() == idMenuAutoVersioning)
409
else if (m_IsCurrentProjectVersioned)
415
else if(event.GetId() == idMenuChangesLog)
438
void AutoVersioning::SetVersionAndSettings(cbProject& Project, bool update)
440
// KILLERBOT : in case our struct would have a constructor, then no need to have an if/else here
441
// --> init in correct place then !!!!!!! TODO
442
m_timerStatus->Stop();
443
avVersionEditorDlg VersionEditorDialog((wxWindow*) Manager::Get()->GetAppWindow(), 0L);
445
VersionEditorDialog.SetCurrentProject(Project.GetTitle());
447
VersionEditorDialog.SetMajor(GetVersionState().Values.Major);
448
VersionEditorDialog.SetMinor(GetVersionState().Values.Minor);
449
VersionEditorDialog.SetBuild(GetVersionState().Values.Build);
450
VersionEditorDialog.SetRevision(GetVersionState().Values.Revision);
451
VersionEditorDialog.SetCount(GetVersionState().Values.BuildCount);
453
VersionEditorDialog.SetAuto(GetConfig().Settings.Autoincrement);
454
VersionEditorDialog.SetDates(GetConfig().Settings.DateDeclarations);
456
VersionEditorDialog.SetSvn(GetConfig().Settings.Svn);
457
VersionEditorDialog.SetSvnDirectory(cbC2U(GetConfig().Settings.SvnDirectory.c_str()));
458
VersionEditorDialog.SetCommit(GetConfig().Settings.DoAutoIncrement);
459
VersionEditorDialog.SetCommitAsk(GetConfig().Settings.AskToIncrement);
460
VersionEditorDialog.SetLanguage(cbC2U(GetConfig().Settings.Language.c_str()));
461
VersionEditorDialog.SetHeaderPath(cbC2U(GetConfig().Settings.HeaderPath.c_str()));
463
VersionEditorDialog.SetStatus(cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
464
VersionEditorDialog.SetStatusAbbreviation(cbC2U(GetVersionState().Status.Abbreviation.c_str()));
466
VersionEditorDialog.SetMinorMaximum(GetConfig().Scheme.MinorMax);
467
VersionEditorDialog.SetBuildMaximum(GetConfig().Scheme.BuildMax);
468
VersionEditorDialog.SetRevisionMaximum(GetConfig().Scheme.RevisionMax);
469
VersionEditorDialog.SetRevisionRandomMaximum(GetConfig().Scheme.RevisionRandMax);
470
VersionEditorDialog.SetBuildTimesToMinorIncrement(GetConfig().Scheme.BuildTimesToIncrementMinor);
472
VersionEditorDialog.SetChanges(GetConfig().ChangesLog.ShowChangesEditor);
473
VersionEditorDialog.SetChangesTitle(cbC2U(GetConfig().ChangesLog.AppTitle.c_str()));
474
VersionEditorDialog.SetChangesLogPath(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()));
476
VersionEditorDialog.ShowModal();
477
// allright let's call all the getters
478
avConfig OldConfig = GetConfig();
479
GetConfig().Scheme.MinorMax = VersionEditorDialog.GetMinorMaximum();
480
GetConfig().Scheme.BuildMax = VersionEditorDialog.GetBuildMaximum();
481
GetConfig().Scheme.RevisionMax = VersionEditorDialog.GetRevisionMaximum();
482
GetConfig().Scheme.RevisionRandMax = VersionEditorDialog.GetRevisionRandomMaximum();
483
GetConfig().Scheme.BuildTimesToIncrementMinor = VersionEditorDialog.GetBuildTimesToMinorIncrement();
484
GetConfig().Settings.Autoincrement = VersionEditorDialog.GetAuto();
485
GetConfig().Settings.DateDeclarations = VersionEditorDialog.GetDates();
486
GetConfig().Settings.AskToIncrement = VersionEditorDialog.GetCommitAsk();
487
GetConfig().Settings.DoAutoIncrement = VersionEditorDialog.GetCommit();
488
GetConfig().Settings.Language = cbU2C(VersionEditorDialog.GetLanguage());
489
GetConfig().Settings.Svn = VersionEditorDialog.GetSvn();
490
GetConfig().Settings.SvnDirectory = cbU2C(VersionEditorDialog.GetSvnDirectory());
491
GetConfig().Settings.HeaderPath = cbU2C(VersionEditorDialog.GetHeaderPath());
492
GetConfig().ChangesLog.ShowChangesEditor = VersionEditorDialog.GetChanges();
493
GetConfig().ChangesLog.AppTitle = cbU2C(VersionEditorDialog.GetChangesTitle());
494
GetConfig().ChangesLog.ChangesLogPath = cbU2C(VersionEditorDialog.GetChangesLogPath());
497
m_versionHeaderPath = cbC2U(GetConfig().Settings.HeaderPath.c_str());
499
if(OldConfig != GetConfig())
500
{ // settings have changed => Project is to be considered changed
501
Project.SetModified(true);
503
// let's update the current version state values in case they were adjusted in the gui
504
// and when the time is right they are put in the version.h (when is that time ???)
420
void AutoVersioning::OnMenuChangesLog(wxCommandEvent&)
425
void AutoVersioning::OnUpdateUI(wxUpdateUIEvent& event)
431
if(event.GetId() == idMenuAutoVersioning)
435
else if (m_IsVersioned[m_Project])
441
else if(event.GetId() == idMenuChangesLog)
464
void AutoVersioning::SetVersionAndSettings(cbProject& Project, bool update)
466
// KILLERBOT : in case our struct would have a constructor, then no need to have an if/else here
467
// --> init in correct place then !!!!!!! TODO
468
m_timerStatus->Stop();
469
avVersionEditorDlg VersionEditorDialog((wxWindow*) Manager::Get()->GetAppWindow(), 0L);
471
VersionEditorDialog.SetCurrentProject(Project.GetTitle());
473
VersionEditorDialog.SetMajor(GetVersionState().Values.Major);
474
VersionEditorDialog.SetMinor(GetVersionState().Values.Minor);
475
VersionEditorDialog.SetBuild(GetVersionState().Values.Build);
476
VersionEditorDialog.SetRevision(GetVersionState().Values.Revision);
477
VersionEditorDialog.SetCount(GetVersionState().Values.BuildCount);
479
VersionEditorDialog.SetAuto(GetConfig().Settings.Autoincrement);
480
VersionEditorDialog.SetDates(GetConfig().Settings.DateDeclarations);
482
VersionEditorDialog.SetSvn(GetConfig().Settings.Svn);
483
VersionEditorDialog.SetSvnDirectory(cbC2U(GetConfig().Settings.SvnDirectory.c_str()));
484
VersionEditorDialog.SetCommit(GetConfig().Settings.DoAutoIncrement);
485
VersionEditorDialog.SetCommitAsk(GetConfig().Settings.AskToIncrement);
486
VersionEditorDialog.SetLanguage(cbC2U(GetConfig().Settings.Language.c_str()));
487
VersionEditorDialog.SetHeaderPath(cbC2U(GetConfig().Settings.HeaderPath.c_str()));
489
VersionEditorDialog.SetStatus(cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
490
VersionEditorDialog.SetStatusAbbreviation(cbC2U(GetVersionState().Status.Abbreviation.c_str()));
492
VersionEditorDialog.SetMinorMaximum(GetConfig().Scheme.MinorMax);
493
VersionEditorDialog.SetBuildMaximum(GetConfig().Scheme.BuildMax);
494
VersionEditorDialog.SetRevisionMaximum(GetConfig().Scheme.RevisionMax);
495
VersionEditorDialog.SetRevisionRandomMaximum(GetConfig().Scheme.RevisionRandMax);
496
VersionEditorDialog.SetBuildTimesToMinorIncrement(GetConfig().Scheme.BuildTimesToIncrementMinor);
498
VersionEditorDialog.SetChanges(GetConfig().ChangesLog.ShowChangesEditor);
499
VersionEditorDialog.SetChangesTitle(cbC2U(GetConfig().ChangesLog.AppTitle.c_str()));
500
VersionEditorDialog.SetChangesLogPath(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()));
502
VersionEditorDialog.SetHeaderGuard(cbC2U(GetConfig().Code.HeaderGuard.c_str()));
503
VersionEditorDialog.SetNamespace(cbC2U(GetConfig().Code.NameSpace.c_str()));
504
VersionEditorDialog.SetPrefix(cbC2U(GetConfig().Code.Prefix.c_str()));
506
VersionEditorDialog.ShowModal();
507
// allright let's call all the getters
508
avConfig OldConfig = GetConfig();
509
GetConfig().Scheme.MinorMax = VersionEditorDialog.GetMinorMaximum();
510
GetConfig().Scheme.BuildMax = VersionEditorDialog.GetBuildMaximum();
511
GetConfig().Scheme.RevisionMax = VersionEditorDialog.GetRevisionMaximum();
512
GetConfig().Scheme.RevisionRandMax = VersionEditorDialog.GetRevisionRandomMaximum();
513
GetConfig().Scheme.BuildTimesToIncrementMinor = VersionEditorDialog.GetBuildTimesToMinorIncrement();
514
GetConfig().Settings.Autoincrement = VersionEditorDialog.GetAuto();
515
GetConfig().Settings.DateDeclarations = VersionEditorDialog.GetDates();
516
GetConfig().Settings.AskToIncrement = VersionEditorDialog.GetCommitAsk();
517
GetConfig().Settings.DoAutoIncrement = VersionEditorDialog.GetCommit();
518
GetConfig().Settings.Language = cbU2C(VersionEditorDialog.GetLanguage());
519
GetConfig().Settings.Svn = VersionEditorDialog.GetSvn();
520
GetConfig().Settings.SvnDirectory = cbU2C(VersionEditorDialog.GetSvnDirectory());
521
GetConfig().Settings.HeaderPath = cbU2C(VersionEditorDialog.GetHeaderPath());
522
GetConfig().ChangesLog.ShowChangesEditor = VersionEditorDialog.GetChanges();
523
GetConfig().ChangesLog.AppTitle = cbU2C(VersionEditorDialog.GetChangesTitle());
524
GetConfig().ChangesLog.ChangesLogPath = cbU2C(VersionEditorDialog.GetChangesLogPath());
525
GetConfig().Code.HeaderGuard = cbU2C(VersionEditorDialog.GetHeaderGuard());
526
GetConfig().Code.NameSpace = cbU2C(VersionEditorDialog.GetNamespace());
527
GetConfig().Code.Prefix = cbU2C(VersionEditorDialog.GetPrefix());
530
m_versionHeaderPath = cbC2U(GetConfig().Settings.HeaderPath.c_str());
532
if(OldConfig != GetConfig())
533
{ // settings have changed => Project is to be considered changed
534
Project.SetModified(true);
536
// let's update the current version state values in case they were adjusted in the gui
537
// and when the time is right they are put in the version.h (when is that time ???)
505
538
avVersionState OldState = GetVersionState();
506
GetVersionState().Values.Major = VersionEditorDialog.GetMajor();
507
GetVersionState().Values.Minor = VersionEditorDialog.GetMinor();
508
GetVersionState().Values.Build = VersionEditorDialog.GetBuild();
509
GetVersionState().Values.Revision = VersionEditorDialog.GetRevision();
510
GetVersionState().Values.BuildCount = VersionEditorDialog.GetCount();
512
GetVersionState().Status.SoftwareStatus = cbU2C(VersionEditorDialog.GetStatus());
513
GetVersionState().Status.Abbreviation = cbU2C(VersionEditorDialog.GetStatusAbbreviation());
516
{ // first time; we just activated the plug-in on the project; clean start
517
GetVersionState().BuildHistory = 0;
520
m_timerStatus->Start(1000);
539
GetVersionState().Values.Major = VersionEditorDialog.GetMajor();
540
GetVersionState().Values.Minor = VersionEditorDialog.GetMinor();
541
GetVersionState().Values.Build = VersionEditorDialog.GetBuild();
542
GetVersionState().Values.Revision = VersionEditorDialog.GetRevision();
543
GetVersionState().Values.BuildCount = VersionEditorDialog.GetCount();
545
GetVersionState().Status.SoftwareStatus = cbU2C(VersionEditorDialog.GetStatus());
546
GetVersionState().Status.Abbreviation = cbU2C(VersionEditorDialog.GetStatusAbbreviation());
549
{ // first time; we just activated the plug-in on the project; clean start
550
GetVersionState().BuildHistory = 0;
553
m_timerStatus->Start(1000);
524
557
KILLERBOT : this method will be called when the user has triggered the Autoversioning through it's main menu entry
525
just after SetVersionAndSettings() has shown the GUI to enter plugin configuration settings and version state variables
527
void AutoVersioning::UpdateVersionHeader()
529
m_timerStatus->Stop();
531
wxString headerOutput = _T("");
532
headerOutput << _T("#ifndef VERSION_H") << _T("\n");
533
headerOutput << _T("#define VERSION_H") << _T("\n");
534
headerOutput << _T("\n");
536
if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
538
headerOutput << _T("namespace AutoVersion{") << _T("\n");
539
headerOutput << _T("\t") << _T("\n");
542
if(GetConfig().Settings.DateDeclarations)
544
wxDateTime actualDate = wxDateTime::Now();
545
headerOutput << _T("\t") << _T("//Date Version Types") << _T("\n");
546
headerOutput << _T("\t") << _T("static const char DATE[] = ") << actualDate.Format(_T("\"%d\"")) << _T(";\n");
547
headerOutput << _T("\t") << _T("static const char MONTH[] = ") << actualDate.Format(_T("\"%m\"")) << _T(";\n");
548
headerOutput << _T("\t") << _T("static const char YEAR[] = ") << actualDate.Format(_T("\"%Y\"")) << _T(";\n");
549
long ubuntuYearNumber = 0;
550
actualDate.Format(_T("%y")).ToLong(&ubuntuYearNumber);
552
ubuntuYear.Printf(_T("%d"),ubuntuYearNumber);
553
headerOutput << _T("\t") << _T("static const double UBUNTU_VERSION_STYLE = ") << ubuntuYear << actualDate.Format(_T(".%m")) << _T(";\n");
554
headerOutput << _T("\t") << _T("\n");
557
headerOutput << _T("\t") << _T("//Software Status") << _T("\n");
558
headerOutput << _T("\t") << _T("static const char STATUS[] = \"") << cbC2U(GetVersionState().Status.SoftwareStatus.c_str()) << _T("\";\n");
559
headerOutput << _T("\t") << _T("static const char STATUS_SHORT[] = \"") << cbC2U(GetVersionState().Status.Abbreviation.c_str()) << _T("\";\n");
560
headerOutput << _T("\t") << _T("\n");
563
headerOutput << _T("\t") << _T("//Standard Version Type") << _T("\n");
564
myPrintf.Printf(_T("%d"), GetVersionState().Values.Major);
565
headerOutput << _T("\t") << _T("static const long MAJOR = ") << myPrintf << _T(";\n");
566
myPrintf.Printf(_T("%d"), GetVersionState().Values.Minor);
567
headerOutput << _T("\t") << _T("static const long MINOR = ") << myPrintf << _T(";\n");
568
myPrintf.Printf(_T("%d"), GetVersionState().Values.Build);
569
headerOutput << _T("\t") << _T("static const long BUILD = ") << myPrintf << _T(";\n");
570
myPrintf.Printf(_T("%d"), GetVersionState().Values.Revision);
571
headerOutput << _T("\t") << _T("static const long REVISION = ") << myPrintf << _T(";\n");
572
headerOutput << _T("\t") << _T("\n");
574
headerOutput << _T("\t") << _T("//Miscellaneous Version Types") << _T("\n");
575
myPrintf.Printf(_T("%d"), GetVersionState().Values.BuildCount);
576
headerOutput << _T("\t") << _T("static const long BUILDS_COUNT = ") << myPrintf << _T(";\n");
578
myPrintf.Printf(_T("%d,%d,%d,%d"), GetVersionState().Values.Major, GetVersionState().Values.Minor,
579
GetVersionState().Values.Build, GetVersionState().Values.Revision);
580
headerOutput << _T("\t") << _T("#define RC_FILEVERSION ") << myPrintf << _T("\n");
582
myPrintf.Printf(_T("\"%d, %d, %d, %d\\0\""), GetVersionState().Values.Major, GetVersionState().Values.Minor,
583
GetVersionState().Values.Build, GetVersionState().Values.Revision);
584
headerOutput << _T("\t") << _T("#define RC_FILEVERSION_STRING ") << myPrintf << _T("\n");
586
myPrintf.Printf(_T("\"%d.%d.%d.%d\""), GetVersionState().Values.Major, GetVersionState().Values.Minor,
587
GetVersionState().Values.Build, GetVersionState().Values.Revision);
588
headerOutput << _T("\t") << _T("static const char FULLVERSION_STRING[] = ") << myPrintf << _T(";\n");
590
if(GetConfig().Settings.Svn)
592
wxString revision,date;
593
if (!QuerySvn(cbC2U(GetConfig().Settings.SvnDirectory.c_str()), revision, date))
594
wxMessageBox(_("Svn configuration files not found.\nVerify the Autoversioning svn directory."),_("Error"),wxICON_ERROR);
595
headerOutput << _T("\t") << _T("\n");
596
headerOutput << _T("\t") << _T("//SVN Version") << _T("\n");
597
headerOutput << _T("\t") << _T("static const char SVN_REVISION[] = ") << _T("\"") + revision + _T("\"")<< _T(";\n");
598
headerOutput << _T("\t") << _T("static const char SVN_DATE[] = ") << _T("\"") + date + _T("\"")<< _T(";\n");
601
headerOutput << _T("\t") << _T("\n");
602
headerOutput << _T("\t") << _T("//These values are to keep track of your versioning state, don't modify them.") << _T("\n");
603
myPrintf.Printf(_T("%d"), GetVersionState().BuildHistory);
604
headerOutput << _T("\t") << _T("static const long BUILD_HISTORY = ") << myPrintf << _T(";\n");
606
headerOutput << _T("\t") << _T("\n\n");
608
if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
610
headerOutput << _T("}") << _T("\n");
613
headerOutput << _T("#endif //VERSION_h\n");
615
m_versionHeaderPath = FileNormalize(cbC2U(GetConfig().Settings.HeaderPath.c_str()),m_Project->GetBasePath());;
616
wxFile versionHeaderFile(m_versionHeaderPath, wxFile::write);
617
versionHeaderFile.Write(headerOutput);
618
versionHeaderFile.Close();
620
m_timerStatus->Start(1000);
623
void AutoVersioning::CommitChanges()
625
if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
629
srand((unsigned)time(0));
630
GetVersionState().Values.Revision += 1 + rand( ) % GetConfig().Scheme.RevisionRandMax;
632
if ((GetConfig().Scheme.RevisionMax != 0) && (GetVersionState().Values.Revision > GetConfig().Scheme.RevisionMax))
634
GetVersionState().Values.Revision = 0;
637
if (GetConfig().Scheme.BuildMax == 0)
639
++GetVersionState().Values.Build;
641
else if(GetVersionState().Values.Build >= GetConfig().Scheme.BuildMax)
643
GetVersionState().Values.Build = 0;
647
++GetVersionState().Values.Build;
649
if(GetConfig().Settings.Autoincrement)
651
++GetVersionState().BuildHistory;
652
if(GetVersionState().BuildHistory >= GetConfig().Scheme.BuildTimesToIncrementMinor)
654
GetVersionState().BuildHistory = 0;
655
++GetVersionState().Values.Minor;
657
if (GetVersionState().Values.Minor > GetConfig().Scheme.MinorMax)
659
GetVersionState().Values.Minor = 0;
660
++GetVersionState().Values.Major;
663
if(GetConfig().ChangesLog.ShowChangesEditor)
558
just after SetVersionAndSettings() has shown the GUI to enter plugin configuration settings and version state variables
560
void AutoVersioning::UpdateVersionHeader()
562
m_timerStatus->Stop();
564
//Declares the header guard to be used based on the filename
565
wxFileName filename(cbC2U(GetConfig().Settings.HeaderPath.c_str()));
566
wxString headerGuard;
568
if(cbC2U(GetConfig().Code.HeaderGuard.c_str()) == _T(""))
570
headerGuard = filename.GetName() + _T("_") + filename.GetExt();
571
headerGuard.Replace(_T(" "), _T("_"), true);
572
headerGuard.UpperCase();
576
headerGuard = cbC2U(GetConfig().Code.HeaderGuard.c_str());
579
wxString prefix = cbC2U(GetConfig().Code.Prefix.c_str());
583
prefix = prefix + _T("_");
586
wxString headerOutput = _T("");
587
headerOutput << _T("#ifndef ") << headerGuard << _T("\n");
588
headerOutput << _T("#define ") << headerGuard << _T("\n");
589
headerOutput << _T("\n");
591
if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
593
headerOutput << _T("namespace ") << cbC2U(GetConfig().Code.NameSpace.c_str()) << _T("{") << _T("\n");
594
headerOutput << _T("\t") << _T("\n");
597
if(GetConfig().Settings.DateDeclarations)
599
wxDateTime actualDate = wxDateTime::Now();
600
headerOutput << _T("\t") << _T("//Date Version Types") << _T("\n");
601
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("DATE[] = ") << actualDate.Format(_T("\"%d\"")) << _T(";\n");
602
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("MONTH[] = ") << actualDate.Format(_T("\"%m\"")) << _T(";\n");
603
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("YEAR[] = ") << actualDate.Format(_T("\"%Y\"")) << _T(";\n");
604
long ubuntuYearNumber = 0;
605
actualDate.Format(_T("%y")).ToLong(&ubuntuYearNumber);
607
ubuntuYear.Printf(_T("%ld"),ubuntuYearNumber);
608
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("UBUNTU_VERSION_STYLE[] = \"") << ubuntuYear << actualDate.Format(_T(".%m")) << _T("\";\n");
609
headerOutput << _T("\t") << _T("\n");
612
headerOutput << _T("\t") << _T("//Software Status") << _T("\n");
613
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("STATUS[] = \"") << cbC2U(GetVersionState().Status.SoftwareStatus.c_str()) << _T("\";\n");
614
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("STATUS_SHORT[] = \"") << cbC2U(GetVersionState().Status.Abbreviation.c_str()) << _T("\";\n");
615
headerOutput << _T("\t") << _T("\n");
618
headerOutput << _T("\t") << _T("//Standard Version Type") << _T("\n");
619
myPrintf.Printf(_T("%ld"), GetVersionState().Values.Major);
620
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("MAJOR = ") << myPrintf << _T(";\n");
621
myPrintf.Printf(_T("%ld"), GetVersionState().Values.Minor);
622
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("MINOR = ") << myPrintf << _T(";\n");
623
myPrintf.Printf(_T("%ld"), GetVersionState().Values.Build);
624
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("BUILD = ") << myPrintf << _T(";\n");
625
myPrintf.Printf(_T("%ld"), GetVersionState().Values.Revision);
626
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("REVISION = ") << myPrintf << _T(";\n");
627
headerOutput << _T("\t") << _T("\n");
629
headerOutput << _T("\t") << _T("//Miscellaneous Version Types") << _T("\n");
630
myPrintf.Printf(_T("%ld"), GetVersionState().Values.BuildCount);
631
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("BUILDS_COUNT = ") << myPrintf << _T(";\n");
633
myPrintf.Printf(_T("%ld,%ld,%ld,%ld"), GetVersionState().Values.Major, GetVersionState().Values.Minor,
634
GetVersionState().Values.Build, GetVersionState().Values.Revision);
635
headerOutput << _T("\t") << _T("#define ") << prefix << _T("RC_FILEVERSION ") << myPrintf << _T("\n");
637
myPrintf.Printf(_T("\"%ld, %ld, %ld, %ld\\0\""), GetVersionState().Values.Major, GetVersionState().Values.Minor,
638
GetVersionState().Values.Build, GetVersionState().Values.Revision);
639
headerOutput << _T("\t") << _T("#define ") << prefix << _T("RC_FILEVERSION_STRING ") << myPrintf << _T("\n");
641
myPrintf.Printf(_T("\"%ld.%ld.%ld.%ld\""), GetVersionState().Values.Major, GetVersionState().Values.Minor,
642
GetVersionState().Values.Build, GetVersionState().Values.Revision);
643
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("FULLVERSION_STRING[] = ") << myPrintf << _T(";\n");
645
if(GetConfig().Settings.Svn)
647
wxString revision,date;
648
if (!QuerySvn(cbC2U(GetConfig().Settings.SvnDirectory.c_str()), revision, date))
649
wxMessageBox(_("Svn configuration files not found.\nVerify the Autoversioning svn directory."),_("Error"),wxICON_ERROR);
650
headerOutput << _T("\t") << _T("\n");
651
headerOutput << _T("\t") << _T("//SVN Version") << _T("\n");
652
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("SVN_REVISION[] = ") << _T("\"") + revision + _T("\"")<< _T(";\n");
653
headerOutput << _T("\t") << _T("static const char ") << prefix << _T("SVN_DATE[] = ") << _T("\"") + date + _T("\"")<< _T(";\n");
656
headerOutput << _T("\t") << _T("\n");
657
headerOutput << _T("\t") << _T("//These values are to keep track of your versioning state, don't modify them.") << _T("\n");
658
myPrintf.Printf(_T("%ld"), GetVersionState().BuildHistory);
659
headerOutput << _T("\t") << _T("static const long ") << prefix << _T("BUILD_HISTORY = ") << myPrintf << _T(";\n");
661
headerOutput << _T("\t") << _T("\n\n");
663
if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
665
headerOutput << _T("}") << _T("\n");
668
headerOutput << _T("#endif //") << headerGuard << _T("\n");
670
m_versionHeaderPath = FileNormalize(cbC2U(GetConfig().Settings.HeaderPath.c_str()),m_Project->GetBasePath());
671
wxFile versionHeaderFile(m_versionHeaderPath, wxFile::write);
672
versionHeaderFile.Write(headerOutput);
673
versionHeaderFile.Close();
675
m_timerStatus->Start(1000);
678
void AutoVersioning::CommitChanges()
680
if (m_Project && IsAttached() && m_IsVersioned[m_Project])
684
srand((unsigned)time(0));
685
GetVersionState().Values.Revision += 1 + rand( ) % GetConfig().Scheme.RevisionRandMax;
687
if ((GetConfig().Scheme.RevisionMax != 0) && (GetVersionState().Values.Revision > GetConfig().Scheme.RevisionMax))
689
GetVersionState().Values.Revision = 0;
692
if (GetConfig().Scheme.BuildMax == 0)
694
++GetVersionState().Values.Build;
696
else if(GetVersionState().Values.Build >= GetConfig().Scheme.BuildMax)
698
GetVersionState().Values.Build = 0;
702
++GetVersionState().Values.Build;
704
if(GetConfig().Settings.Autoincrement)
706
++GetVersionState().BuildHistory;
707
if(GetVersionState().BuildHistory >= GetConfig().Scheme.BuildTimesToIncrementMinor)
709
GetVersionState().BuildHistory = 0;
710
++GetVersionState().Values.Minor;
712
if (GetVersionState().Values.Minor > GetConfig().Scheme.MinorMax)
714
GetVersionState().Values.Minor = 0;
715
++GetVersionState().Values.Major;
718
if(GetConfig().ChangesLog.ShowChangesEditor)
665
720
GenerateChanges();
667
722
m_Project->SaveAllFiles();
670
725
UpdateVersionHeader();
675
void AutoVersioning::GenerateChanges()
677
avChangesDlg changesDlg((wxWindow*) Manager::Get()->GetAppWindow(),0L);
678
changesDlg.SetTemporaryChangesFile(m_Project->GetBasePath() + _T("changes.tmp"));
679
changesDlg.ShowModal();
681
wxString changes = changesDlg.Changes();
683
if (!changes.IsEmpty())
685
changes.Prepend(_T(" -"));
686
changes.Replace(_T("\n"), _T("\n -"));
688
wxDateTime actualDate = wxDateTime::Now();
730
void AutoVersioning::GenerateChanges()
732
avChangesDlg changesDlg((wxWindow*) Manager::Get()->GetAppWindow(),0L);
733
changesDlg.SetTemporaryChangesFile(m_Project->GetBasePath() + _T("changes.tmp"));
734
changesDlg.ShowModal();
736
wxString changes = changesDlg.Changes();
738
if (!changes.IsEmpty())
740
changes.Prepend(_T(" -"));
741
changes.Replace(_T("\n"), _T("\n -"));
743
wxDateTime actualDate = wxDateTime::Now();
689
744
wxString changesTitle = cbC2U(GetConfig().ChangesLog.AppTitle.c_str());
691
changesTitle.Replace(_T("%d"), actualDate.Format(_T("%d")));
692
changesTitle.Replace(_T("%o"), actualDate.Format(_T("%m")));
693
changesTitle.Replace(_T("%y"), actualDate.Format(_T("%Y")));
746
changesTitle.Replace(_T("%d"), actualDate.Format(_T("%d")));
747
changesTitle.Replace(_T("%o"), actualDate.Format(_T("%m")));
748
changesTitle.Replace(_T("%y"), actualDate.Format(_T("%Y")));
696
value.Printf(_T("%d"), GetVersionState().Values.Major);
697
changesTitle.Replace(_T("%M"), value);
699
value.Printf(_T("%d"), GetVersionState().Values.Minor);
700
changesTitle.Replace(_T("%m"), value);
702
value.Printf(_T("%d"), GetVersionState().Values.Build);
703
changesTitle.Replace(_T("%b"), value);
705
value.Printf(_T("%d"), GetVersionState().Values.Revision);
706
changesTitle.Replace(_T("%r"), value);
708
value.Printf(_T("%d"), GetConfig().Settings.Svn?1:0);
709
changesTitle.Replace(_T("%s"),value);
711
changesTitle.Replace(_T("%T"), cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
712
changesTitle.Replace(_T("%t"), cbC2U(GetVersionState().Status.Abbreviation.c_str()));
713
changesTitle.Replace(_T("%p"), m_Project->GetTitle());
715
wxString changesFile = FileNormalize(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()), m_Project->GetBasePath());
716
wxString changesCurrentContent;
717
if (wxFile::Exists(changesFile))
721
file.Open(changesFile);
722
file.ReadAll(&changesCurrentContent);
726
wxString changesOutput = _T("");
728
changesOutput << actualDate.Format(_T("%d %B %Y\n"));
729
changesOutput << _T(" ") << changesTitle << _T("\n");
730
changesOutput << _T("\n Change log:\n");
731
changesOutput << changes << _T("\n\n");
732
changesOutput << changesCurrentContent;
735
file.Open(changesFile,wxFile::write);
736
file.Write(changesOutput);
739
}//If not changes.IsEmpty()
742
wxString AutoVersioning::FileNormalize(const wxString& relativeFile, const wxString& workingDirectory)
744
wxFileName fileNormalize(relativeFile);
745
if(fileNormalize.Normalize(wxPATH_NORM_ABSOLUTE,workingDirectory))
747
//If everything is ok returns absolute path
748
return fileNormalize.GetFullPath();
752
//If something goes wrong return project's cwd and filename with extension.
753
return workingDirectory + fileNormalize.GetName() + fileNormalize.GetExt();
751
value.Printf(_T("%ld"), GetVersionState().Values.Major);
752
changesTitle.Replace(_T("%M"), value);
754
value.Printf(_T("%ld"), GetVersionState().Values.Minor);
755
changesTitle.Replace(_T("%m"), value);
757
value.Printf(_T("%ld"), GetVersionState().Values.Build);
758
changesTitle.Replace(_T("%b"), value);
760
value.Printf(_T("%ld"), GetVersionState().Values.Revision);
761
changesTitle.Replace(_T("%r"), value);
763
value.Printf(_T("%d"), GetConfig().Settings.Svn?1:0);
764
changesTitle.Replace(_T("%s"),value);
766
changesTitle.Replace(_T("%T"), cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
767
changesTitle.Replace(_T("%t"), cbC2U(GetVersionState().Status.Abbreviation.c_str()));
768
changesTitle.Replace(_T("%p"), m_Project->GetTitle());
770
wxString changesFile = FileNormalize(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()), m_Project->GetBasePath());
771
wxString changesCurrentContent;
772
if (wxFile::Exists(changesFile))
776
file.Open(changesFile);
777
file.ReadAll(&changesCurrentContent);
781
wxString changesOutput = _T("");
783
changesOutput << actualDate.Format(_T("%d %B %Y\n"));
784
changesOutput << _T(" ") << changesTitle << _T("\n");
785
changesOutput << _T("\n Change log:\n");
786
changesOutput << changes << _T("\n\n");
787
changesOutput << changesCurrentContent;
790
file.Open(changesFile,wxFile::write);
791
file.Write(changesOutput);
794
}//If not changes.IsEmpty()
797
wxString AutoVersioning::FileNormalize(const wxString& relativeFile, const wxString& workingDirectory)
799
wxFileName fileNormalize(relativeFile);
800
if(fileNormalize.Normalize(wxPATH_NORM_ABSOLUTE,workingDirectory))
802
//If everything is ok returns absolute path
803
return fileNormalize.GetFullPath();
807
//If something goes wrong return project's cwd and filename with extension.
808
return workingDirectory + fileNormalize.GetName() + fileNormalize.GetExt();
757
812
avConfig& AutoVersioning::GetConfig()