~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/AutoVersioning/AutoVersioning.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <ctime>
2
2
#include <cstdlib> //For random numbers
3
 
#include <sdk.h>
4
 
 
5
 
#ifndef CB_PRECOMP
6
 
#include <wx/file.h>
7
 
#include <wx/filefn.h>
8
 
#include <wx/ffile.h>
9
 
#include <wx/filename.h>
10
 
#include <wx/intl.h>
11
 
#include <wx/menu.h>
12
 
#include <wx/msgdlg.h>
13
 
#include <wx/timer.h>
14
 
#include <cbproject.h>
 
3
#include <sdk.h>
 
4
 
 
5
#ifndef CB_PRECOMP
 
6
#include <wx/dynarray.h>
 
7
#include <wx/file.h>
 
8
#include <wx/filefn.h>
 
9
#include <wx/ffile.h>
 
10
#include <wx/filename.h>
 
11
#include <wx/intl.h>
 
12
#include <wx/menu.h>
 
13
#include <wx/msgdlg.h>
 
14
#include <wx/timer.h>
 
15
#include <cbproject.h>
15
16
#include "globals.h"
16
 
#include <manager.h>
17
 
#include <projectbuildtarget.h>
18
 
#include <projectmanager.h>
 
17
#include <manager.h>
 
18
#include <projectbuildtarget.h>
 
19
#include <projectmanager.h>
19
20
#include <tinyxml/tinyxml.h>
20
 
#endif
21
 
 
 
21
#endif
 
22
 
22
23
#include "projectloader_hooks.h"
23
24
 
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"
29
 
 
30
 
using namespace std;
31
 
 
32
 
const int idMenuAutoVersioning = wxNewId();
33
 
const int idMenuCommitChanges = wxNewId();
34
 
const int idMenuChangesLog = wxNewId();
35
 
 
36
 
/*
37
 
        KILLERBOT : TODO : is this really needed  ??
38
 
    EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
39
 
    EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
40
 
*/
41
 
 
42
 
 
43
 
//{Event Table
44
 
BEGIN_EVENT_TABLE(AutoVersioning,wxEvtHandler)
45
 
    EVT_TIMER(-1, AutoVersioning::OnTimerVerify)
46
 
 
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)
53
 
END_EVENT_TABLE()
54
 
//}
55
 
 
56
 
namespace
57
 
{
58
 
    PluginRegistrant<AutoVersioning> reg(_T("AutoVersioning"));
59
 
}
60
 
 
61
 
//{Constructor and Destructor
62
 
AutoVersioning::AutoVersioning()
 
30
 
 
31
using namespace std;
 
32
 
 
33
const int idMenuAutoVersioning = wxNewId();
 
34
const int idMenuCommitChanges = wxNewId();
 
35
const int idMenuChangesLog = wxNewId();
 
36
 
 
37
/*
 
38
    KILLERBOT : TODO : is this really needed  ??
 
39
    EVT_UPDATE_UI(idMenuCommitChanges, AutoVersioning::OnUpdateUI)
 
40
    EVT_UPDATE_UI(idMenuAutoVersioning, AutoVersioning::OnUpdateUI)
 
41
*/
 
42
 
 
43
 
 
44
//{Event Table
 
45
BEGIN_EVENT_TABLE(AutoVersioning,wxEvtHandler)
 
46
    EVT_TIMER(-1, AutoVersioning::OnTimerVerify)
 
47
 
 
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)
 
54
END_EVENT_TABLE()
 
55
//}
 
56
 
 
57
namespace
 
58
{
 
59
    PluginRegistrant<AutoVersioning> reg(_T("AutoVersioning"));
 
60
}
 
61
 
 
62
//{Constructor and Destructor
 
63
AutoVersioning::AutoVersioning()
63
64
{
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;
70
70
    m_Project = 0;
71
 
} // end of constructor
72
 
 
73
 
AutoVersioning::~AutoVersioning()
 
71
} // end of constructor
 
72
 
 
73
AutoVersioning::~AutoVersioning()
74
74
{
75
75
    ProjectLoaderHooks::UnregisterHook(m_AutoVerHookId, true);
76
 
} // end of destructor
77
 
//}
78
 
 
79
 
//{Virtual overrides
80
 
void AutoVersioning::OnAttach()
81
 
{
82
 
    if (!IsAttached())
83
 
    {
84
 
        wxMessageBox(_("Error loading AutoVersioning Plugin!"),_("Error"),wxICON_ERROR );
85
 
    }
86
 
 
87
 
    m_timerStatus = new wxTimer(this,30000);
88
 
    m_timerStatus->Start(1000);
89
 
 
90
 
    //Register functions to events
 
76
} // end of destructor
 
77
//}
 
78
 
 
79
//{Virtual overrides
 
80
void AutoVersioning::OnAttach()
 
81
{
 
82
    if (!IsAttached())
 
83
    {
 
84
        wxMessageBox(_("Error loading AutoVersioning Plugin!"),_("Error"),wxICON_ERROR );
 
85
    }
 
86
 
 
87
    m_timerStatus = new wxTimer(this,30000);
 
88
    m_timerStatus->Start(1000);
 
89
 
 
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]
97
 
}
98
 
 
99
 
void AutoVersioning::OnRelease(bool appShutDown)
100
 
{
101
 
    if (m_timerStatus->IsRunning())
102
 
    {
103
 
        m_timerStatus->Stop();
104
 
    }
105
 
    delete m_timerStatus;
106
 
    m_timerStatus = 0;
107
 
}
108
 
 
109
 
void AutoVersioning::BuildMenu(wxMenuBar* menuBar)
110
 
{
111
 
    int idProject = menuBar->FindMenu(_("Project"));
112
 
    if (idProject != wxNOT_FOUND)
113
 
    {
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"));
119
 
    }
120
 
}
121
 
//}
122
 
 
123
 
//{Envent Functions
 
96
    //NOTE : all those registered through EventSink don't need to call event.skip() [that is only needed when going through wx]
 
97
}
 
98
 
 
99
void AutoVersioning::OnRelease(bool appShutDown)
 
100
{
 
101
    if (m_timerStatus->IsRunning())
 
102
    {
 
103
        m_timerStatus->Stop();
 
104
    }
 
105
    delete m_timerStatus;
 
106
    m_timerStatus = 0;
 
107
}
 
108
 
 
109
void AutoVersioning::BuildMenu(wxMenuBar* menuBar)
 
110
{
 
111
    int idProject = menuBar->FindMenu(_("&Project"));
 
112
    if (idProject != wxNOT_FOUND)
 
113
    {
 
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"));
 
119
    }
 
120
}
 
121
//}
 
122
 
 
123
//{Envent Functions
124
124
void AutoVersioning::OnProjectLoadingHook(cbProject* project, TiXmlElement* elem, bool loading)
125
125
{
126
 
        if(loading)
127
 
        {
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
130
 
                avConfig Config;
131
 
                m_IsCurrentProjectVersioned = false; // default not active unless we find xml for it
132
 
                const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning");
133
 
                if (Node)
134
 
                {
135
 
                        m_IsCurrentProjectVersioned = true;
136
 
                        TiXmlHandle Handle(const_cast<TiXmlElement*>(Node));
137
 
                        if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement())
138
 
                        {
139
 
                                int Help = 0;
140
 
                                if(pElem->QueryIntAttribute("minor_max", &Help) == TIXML_SUCCESS)
141
 
                                {
142
 
                                        Config.Scheme.MinorMax = static_cast<long>(Help);
143
 
                                }
144
 
                                if(pElem->QueryIntAttribute("build_max", &Help) == TIXML_SUCCESS)
145
 
                                {
146
 
                                        Config.Scheme.BuildMax = static_cast<long>(Help);
147
 
                                }
148
 
                                if(pElem->QueryIntAttribute("rev_max", &Help) == TIXML_SUCCESS)
149
 
                                {
150
 
                                        Config.Scheme.RevisionMax = static_cast<long>(Help);
151
 
                                }
152
 
                                if(pElem->QueryIntAttribute("rev_rand_max", &Help) == TIXML_SUCCESS)
153
 
                                {
154
 
                                        Config.Scheme.RevisionRandMax = static_cast<long>(Help);
155
 
                                }
156
 
                                if(pElem->QueryIntAttribute("build_times_to_increment_minor", &Help) == TIXML_SUCCESS)
157
 
                                {
158
 
                                        Config.Scheme.BuildTimesToIncrementMinor = static_cast<long>(Help);
159
 
                                }
160
 
                        }
161
 
                        if(const TiXmlElement* pElem = Handle.FirstChildElement("Settings").ToElement())
162
 
                        {
163
 
                                Config.Settings.Language = pElem->Attribute("language");
164
 
                                Config.Settings.SvnDirectory = pElem->Attribute("svn_directory");
165
 
                                Config.Settings.HeaderPath = pElem->Attribute("header_path");
166
 
 
167
 
                                int Help = 0;
168
 
                                if(pElem->QueryIntAttribute("autoincrement", &Help) == TIXML_SUCCESS)
169
 
                                {
170
 
                                        Config.Settings.Autoincrement = Help?true:false;
171
 
                                }
172
 
                                if(pElem->QueryIntAttribute("date_declarations", &Help) == TIXML_SUCCESS)
173
 
                                {
174
 
                                        Config.Settings.DateDeclarations = Help?true:false;
175
 
                                }
176
 
                                if(pElem->QueryIntAttribute("do_auto_increment", &Help) == TIXML_SUCCESS)
177
 
                                {
178
 
                                        Config.Settings.DoAutoIncrement = Help?true:false;
179
 
                                }
180
 
                                if(pElem->QueryIntAttribute("ask_to_increment", &Help) == TIXML_SUCCESS)
181
 
                                {
182
 
                                        Config.Settings.AskToIncrement = Help?true:false;
183
 
                                }
184
 
                                if(pElem->QueryIntAttribute("svn", &Help) == TIXML_SUCCESS)
185
 
                                {
186
 
                                        Config.Settings.Svn = Help?true:false;
187
 
                                }
188
 
                        }
189
 
                        if(const TiXmlElement* pElem = Handle.FirstChildElement("Changes_Log").ToElement())
190
 
                        {
191
 
                                Config.ChangesLog.AppTitle = pElem->Attribute("app_title");
192
 
                                Config.ChangesLog.ChangesLogPath = pElem->Attribute("changeslog_path");
193
 
 
194
 
                                int Help = 0;
195
 
                                if(pElem->QueryIntAttribute("show_changes_editor", &Help) == TIXML_SUCCESS)
196
 
                                {
197
 
                                        Config.ChangesLog.ShowChangesEditor = Help?true:false;
198
 
                                }
199
 
                        }
200
 
                }
201
 
                avVersionState VersionState;
202
 
                m_versionHeaderPath = FileNormalize(cbC2U(Config.Settings.HeaderPath.c_str()),project->GetBasePath());
203
 
 
204
 
                avHeader VersionHeader;
 
126
    if(loading)
 
127
    {
 
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
 
130
        avConfig Config;
 
131
        m_IsVersioned[project] = false; // default not active unless we find xml for it
 
132
        const TiXmlElement* Node = elem->FirstChildElement("AutoVersioning");
 
133
        if (Node)
 
134
        {
 
135
            m_IsVersioned[project] = true;
 
136
            TiXmlHandle Handle(const_cast<TiXmlElement*>(Node));
 
137
            if(const TiXmlElement* pElem = Handle.FirstChildElement("Scheme").ToElement())
 
138
            {
 
139
                int Help = 0;
 
140
                if(pElem->QueryIntAttribute("minor_max", &Help) == TIXML_SUCCESS)
 
141
                {
 
142
                    Config.Scheme.MinorMax = static_cast<long>(Help);
 
143
                }
 
144
                if(pElem->QueryIntAttribute("build_max", &Help) == TIXML_SUCCESS)
 
145
                {
 
146
                    Config.Scheme.BuildMax = static_cast<long>(Help);
 
147
                }
 
148
                if(pElem->QueryIntAttribute("rev_max", &Help) == TIXML_SUCCESS)
 
149
                {
 
150
                    Config.Scheme.RevisionMax = static_cast<long>(Help);
 
151
                }
 
152
                if(pElem->QueryIntAttribute("rev_rand_max", &Help) == TIXML_SUCCESS)
 
153
                {
 
154
                    Config.Scheme.RevisionRandMax = static_cast<long>(Help);
 
155
                }
 
156
                if(pElem->QueryIntAttribute("build_times_to_increment_minor", &Help) == TIXML_SUCCESS)
 
157
                {
 
158
                    Config.Scheme.BuildTimesToIncrementMinor = static_cast<long>(Help);
 
159
                }
 
160
            }
 
161
            if(const TiXmlElement* pElem = Handle.FirstChildElement("Settings").ToElement())
 
162
            {
 
163
                Config.Settings.Language = pElem->Attribute("language");
 
164
                Config.Settings.SvnDirectory = pElem->Attribute("svn_directory");
 
165
                Config.Settings.HeaderPath = pElem->Attribute("header_path");
 
166
 
 
167
                int Help = 0;
 
168
                if(pElem->QueryIntAttribute("autoincrement", &Help) == TIXML_SUCCESS)
 
169
                {
 
170
                    Config.Settings.Autoincrement = Help?true:false;
 
171
                }
 
172
                if(pElem->QueryIntAttribute("date_declarations", &Help) == TIXML_SUCCESS)
 
173
                {
 
174
                    Config.Settings.DateDeclarations = Help?true:false;
 
175
                }
 
176
                if(pElem->QueryIntAttribute("do_auto_increment", &Help) == TIXML_SUCCESS)
 
177
                {
 
178
                    Config.Settings.DoAutoIncrement = Help?true:false;
 
179
                }
 
180
                if(pElem->QueryIntAttribute("ask_to_increment", &Help) == TIXML_SUCCESS)
 
181
                {
 
182
                    Config.Settings.AskToIncrement = Help?true:false;
 
183
                }
 
184
                if(pElem->QueryIntAttribute("svn", &Help) == TIXML_SUCCESS)
 
185
                {
 
186
                    Config.Settings.Svn = Help?true:false;
 
187
                }
 
188
            }
 
189
            if(const TiXmlElement* pElem = Handle.FirstChildElement("Code").ToElement())
 
190
            {
 
191
                Config.Code.HeaderGuard = pElem->Attribute("header_guard");
 
192
                Config.Code.NameSpace = pElem->Attribute("namespace");
 
193
                Config.Code.Prefix = pElem->Attribute("prefix");
 
194
            }
 
195
            if(const TiXmlElement* pElem = Handle.FirstChildElement("Changes_Log").ToElement())
 
196
            {
 
197
                Config.ChangesLog.AppTitle = pElem->Attribute("app_title");
 
198
                Config.ChangesLog.ChangesLogPath = pElem->Attribute("changeslog_path");
 
199
 
 
200
                int Help = 0;
 
201
                if(pElem->QueryIntAttribute("show_changes_editor", &Help) == TIXML_SUCCESS)
 
202
                {
 
203
                    Config.ChangesLog.ShowChangesEditor = Help?true:false;
 
204
                }
 
205
            }
 
206
        }
 
207
        avVersionState VersionState;
 
208
        m_versionHeaderPath = FileNormalize(cbC2U(Config.Settings.HeaderPath.c_str()),project->GetBasePath());
 
209
 
 
210
        avHeader VersionHeader;
205
211
        if(VersionHeader.LoadFile(m_versionHeaderPath))
206
212
        {
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"));
215
 
        }
216
 
                m_ProjectMap[project] = Config;
217
 
                m_ProjectMapVersionState[project] = VersionState;
218
 
                m_Project = project;
219
 
        }
220
 
        else
221
 
        {
222
 
                // Hook called when saving project file.
223
 
 
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)
230
 
                {
231
 
                        TiXmlElement* node = elem->FirstChildElement("AutoVersioning");
232
 
                        if (!node)
233
 
                        {
234
 
                                node = elem->InsertEndChild(TiXmlElement("AutoVersioning"))->ToElement();
235
 
                        }
236
 
                        node->Clear();
237
 
 
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];
242
 
 
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);
265
 
                }
266
 
                // TODO (KILLERBOT) : what if we decide to not version anymore : how to remove ??
267
 
        }
 
220
            VersionState.BuildHistory = VersionHeader.GetValue(_("BUILD_HISTORY"));
 
221
        }
 
222
        m_ProjectMap[project] = Config;
 
223
        m_ProjectMapVersionState[project] = VersionState;
 
224
    }
 
225
    else
 
226
    {
 
227
        // Hook called when saving project file.
 
228
 
 
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])
 
235
        {
 
236
            TiXmlElement* node = elem->FirstChildElement("AutoVersioning");
 
237
            if (!node)
 
238
            {
 
239
                node = elem->InsertEndChild(TiXmlElement("AutoVersioning"))->ToElement();
 
240
            }
 
241
            node->Clear();
 
242
 
 
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];
 
247
 
 
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);
 
275
        }
 
276
        // TODO (KILLERBOT) : what if we decide to not version anymore : how to remove ??
 
277
    }
268
278
}// OnProjectLoadingHook
269
279
 
270
280
void AutoVersioning::OnProjectActivated(CodeBlocksEvent& event)
271
281
{
272
 
        if (IsAttached())
273
 
        {
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();
276
 
        }
 
282
    if (IsAttached())
 
283
    {
 
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();
 
286
    }
277
287
}// OnProjectActivated
278
288
 
279
289
void AutoVersioning::OnProjectClosed(CodeBlocksEvent& event)
280
290
{
281
 
        if (IsAttached())
282
 
        {
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 ??)
287
 
                    m_Project = 0;
288
 
                }
289
 
        }
 
291
    if (IsAttached())
 
292
    {
 
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 ??)
 
298
            m_Project = 0;
 
299
        }
 
300
    }
290
301
}// OnProjectClosed
291
302
 
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)
296
 
{
297
 
    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
298
 
    {
299
 
                if (m_Modified)
300
 
                {
301
 
                        const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
302
 
                        const bool askToIncrement = GetConfig().Settings.AskToIncrement;
303
 
                        if (doAutoIncrement && askToIncrement)
304
 
                        {
305
 
                                if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
306
 
                                {
307
 
                                        CommitChanges();
308
 
                                }
309
 
                        }
310
 
                        else if(doAutoIncrement)
311
 
                        {
312
 
                                CommitChanges();
313
 
                        }
314
 
                }
315
 
    }
316
 
} // end of OnCompilerStarted
317
 
 
318
 
void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
319
 
{
320
 
    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
321
 
        {
322
 
                ++(GetVersionState().Values.BuildCount);
323
 
        }
324
 
} // end of OnCompilerFinished
325
 
 
326
 
void AutoVersioning::OnTimerVerify(wxTimerEvent& event)
327
 
{
328
 
    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
329
 
    {
330
 
                if (!m_Modified)
331
 
                {
332
 
                        for (int i=0; i < m_Project->GetFilesCount(); ++i)
333
 
                        {
334
 
                                const ProjectFile* file = m_Project->GetFile(i);
335
 
                                if (file->GetFileState() == fvsModified)
336
 
                                {
337
 
                                        m_Modified = true;
338
 
                                        break;
339
 
                                }
340
 
                        }
341
 
                }
342
 
    }
343
 
} // end of OnTimerVerify
344
 
 
345
 
void AutoVersioning::OnMenuAutoVersioning(wxCommandEvent&)
346
 
{
347
 
    if (IsAttached())
348
 
    {
349
 
        if (m_Project)
350
 
        {
351
 
            if (m_IsCurrentProjectVersioned)
352
 
            {
353
 
                SetVersionAndSettings(*m_Project, true);
354
 
                UpdateVersionHeader();
355
 
            }
356
 
            else
357
 
            {
358
 
                if (wxMessageBox(_("Configure the project \"") + m_Project->GetTitle() + _("\" for Autoversioning?"),_("Autoversioning"),wxYES_NO) == wxYES)
359
 
                {
360
 
                                        // we activated
361
 
                                        m_IsCurrentProjectVersioned = true;
362
 
                                        // just becasue we activated the project becomes modified
363
 
                                        m_Project->SetModified();
364
 
 
365
 
                    SetVersionAndSettings(*m_Project);
366
 
                    UpdateVersionHeader();
367
 
 
368
 
                    for (int i = 1; i < m_Project->GetBuildTargetsCount(); ++i)
369
 
                    {
370
 
                        m_Project->AddFile(i, m_versionHeaderPath, true, true, 0);
371
 
                    }
372
 
                    wxMessageBox(_("Project configured!"));
373
 
                }
374
 
            }
375
 
        }
376
 
        else
377
 
        {
378
 
            cbMessageBox(_("No active project!"), _("Error"), wxICON_ERROR | wxOK);
379
 
        }
380
 
    }
381
 
}
382
 
 
383
 
void AutoVersioning::OnMenuCommitChanges(wxCommandEvent&)
384
 
{
385
 
    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
 
305
// be activated and each has the compilerstarted/Finished ?????
 
306
void AutoVersioning::OnCompilerStarted(CodeBlocksEvent& event)
 
307
{
 
308
    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])
 
309
    {
 
310
        if (m_Modified)
 
311
        {
 
312
            const bool doAutoIncrement = GetConfig().Settings.DoAutoIncrement;
 
313
            const bool askToIncrement = GetConfig().Settings.AskToIncrement;
 
314
            if (doAutoIncrement && askToIncrement)
 
315
            {
 
316
                if (wxMessageBox(_("Do you want to increment the version?"),_T(""),wxYES_NO) == wxYES)
 
317
                {
 
318
                    CommitChanges();
 
319
                }
 
320
            }
 
321
            else if(doAutoIncrement)
 
322
            {
 
323
                CommitChanges();
 
324
            }
 
325
        }
 
326
    }
 
327
} // end of OnCompilerStarted
 
328
 
 
329
void AutoVersioning::OnCompilerFinished(CodeBlocksEvent& event)
 
330
{
 
331
    if (m_Project && IsAttached() && m_IsVersioned[event.GetProject()])
 
332
    {
 
333
        ++(GetVersionState().Values.BuildCount);
 
334
    }
 
335
} // end of OnCompilerFinished
 
336
 
 
337
void AutoVersioning::OnTimerVerify(wxTimerEvent& event)
 
338
{
 
339
    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
 
340
    {
 
341
        if (!m_Modified)
 
342
        {
 
343
            for (int i=0; i < m_Project->GetFilesCount(); ++i)
 
344
            {
 
345
                const ProjectFile* file = m_Project->GetFile(i);
 
346
                if (file->GetFileState() == fvsModified)
 
347
                {
 
348
                    m_Modified = true;
 
349
                    break;
 
350
                }
 
351
            }
 
352
        }
 
353
    }
 
354
} // end of OnTimerVerify
 
355
 
 
356
void AutoVersioning::OnMenuAutoVersioning(wxCommandEvent&)
 
357
{
 
358
    if (IsAttached())
 
359
    {
 
360
        if (m_Project)
 
361
        {
 
362
            if (m_IsVersioned[m_Project])
 
363
            {
 
364
                SetVersionAndSettings(*m_Project, true);
 
365
                UpdateVersionHeader();
 
366
            }
 
367
            else
 
368
            {
 
369
                if (wxMessageBox(_("Configure the project \"") + m_Project->GetTitle() + _("\" for Autoversioning?"),_("Autoversioning"),wxYES_NO) == wxYES)
 
370
                {
 
371
                    if(wxFileExists(m_Project->GetBasePath() + _T("version.h")))
 
372
                    {
 
373
                        wxMessageBox(
 
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."
 
377
                           ),
 
378
                         _T("Warning"),
 
379
                         wxICON_EXCLAMATION  | wxOK
 
380
                        );
 
381
                    }
 
382
 
 
383
                    // we activated
 
384
                    m_IsVersioned[m_Project] = true;
 
385
                    // just becasue we activated the project becomes modified
 
386
                    m_Project->SetModified();
 
387
 
 
388
                    SetVersionAndSettings(*m_Project);
 
389
                    UpdateVersionHeader();
 
390
 
 
391
                    wxArrayInt target_array;
 
392
                    for (int i = 0; i < m_Project->GetBuildTargetsCount(); ++i)
 
393
                    {
 
394
                        target_array.Add(i);
 
395
                    }
 
396
                    Manager::Get()->GetProjectManager()->AddFileToProject(m_versionHeaderPath, m_Project, target_array);
 
397
                    Manager::Get()->GetProjectManager()->RebuildTree();
 
398
                    wxMessageBox(_("Project configured!"));
 
399
                }
 
400
            }
 
401
        }
 
402
        else
 
403
        {
 
404
            cbMessageBox(_("No active project!"), _("Error"), wxICON_ERROR | wxOK);
 
405
        }
 
406
    }
 
407
}
 
408
 
 
409
void AutoVersioning::OnMenuCommitChanges(wxCommandEvent&)
 
410
{
 
411
    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
386
412
    {
387
413
        if(m_Modified)
388
 
        {
389
 
            CommitChanges();
390
 
        }
391
 
    }
392
 
}
393
 
 
394
 
void AutoVersioning::OnMenuChangesLog(wxCommandEvent&)
395
 
{
396
 
    GenerateChanges();
397
 
}
398
 
 
399
 
void AutoVersioning::OnUpdateUI(wxUpdateUIEvent& event)
400
 
{
401
 
    if (IsAttached())
402
 
    {
403
 
        if (m_Project)
404
 
        {
405
 
            if(event.GetId() == idMenuAutoVersioning)
406
 
            {
407
 
                event.Enable(true);
408
 
            }
409
 
            else if (m_IsCurrentProjectVersioned)
410
 
            {
411
 
                if (m_Modified)
412
 
                {
413
 
                    event.Enable(true);
414
 
                }
415
 
                else if(event.GetId() == idMenuChangesLog)
416
 
                {
417
 
                    event.Enable(true);
418
 
                }
419
 
                else
420
 
                {
421
 
                    event.Enable(false);
422
 
                }
423
 
            }
424
 
            else
425
 
            {
426
 
                event.Enable(false);
427
 
            }
428
 
        }
429
 
        else
430
 
        {
431
 
            event.Enable(false);
432
 
        }
433
 
    }
434
 
}
435
 
//}
436
 
 
437
 
//{Functions
438
 
void AutoVersioning::SetVersionAndSettings(cbProject& Project, bool update)
439
 
{
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);
444
 
 
445
 
    VersionEditorDialog.SetCurrentProject(Project.GetTitle());
446
 
 
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);
452
 
 
453
 
    VersionEditorDialog.SetAuto(GetConfig().Settings.Autoincrement);
454
 
    VersionEditorDialog.SetDates(GetConfig().Settings.DateDeclarations);
455
 
 
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()));
462
 
 
463
 
    VersionEditorDialog.SetStatus(cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
464
 
    VersionEditorDialog.SetStatusAbbreviation(cbC2U(GetVersionState().Status.Abbreviation.c_str()));
465
 
 
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);
471
 
 
472
 
    VersionEditorDialog.SetChanges(GetConfig().ChangesLog.ShowChangesEditor);
473
 
    VersionEditorDialog.SetChangesTitle(cbC2U(GetConfig().ChangesLog.AppTitle.c_str()));
474
 
    VersionEditorDialog.SetChangesLogPath(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()));
475
 
 
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());
495
 
 
496
 
    //Save Header path
497
 
    m_versionHeaderPath = cbC2U(GetConfig().Settings.HeaderPath.c_str());
498
 
 
499
 
    if(OldConfig != GetConfig())
500
 
    {   // settings have changed => Project is to be considered changed
501
 
        Project.SetModified(true);
502
 
    }
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 ???)
 
414
        {
 
415
            CommitChanges();
 
416
        }
 
417
    }
 
418
}
 
419
 
 
420
void AutoVersioning::OnMenuChangesLog(wxCommandEvent&)
 
421
{
 
422
    GenerateChanges();
 
423
}
 
424
 
 
425
void AutoVersioning::OnUpdateUI(wxUpdateUIEvent& event)
 
426
{
 
427
    if (IsAttached())
 
428
    {
 
429
        if (m_Project)
 
430
        {
 
431
            if(event.GetId() == idMenuAutoVersioning)
 
432
            {
 
433
                event.Enable(true);
 
434
            }
 
435
            else if (m_IsVersioned[m_Project])
 
436
            {
 
437
                if (m_Modified)
 
438
                {
 
439
                    event.Enable(true);
 
440
                }
 
441
                else if(event.GetId() == idMenuChangesLog)
 
442
                {
 
443
                    event.Enable(true);
 
444
                }
 
445
                else
 
446
                {
 
447
                    event.Enable(false);
 
448
                }
 
449
            }
 
450
            else
 
451
            {
 
452
                event.Enable(false);
 
453
            }
 
454
        }
 
455
        else
 
456
        {
 
457
            event.Enable(false);
 
458
        }
 
459
    }
 
460
}
 
461
//}
 
462
 
 
463
//{Functions
 
464
void AutoVersioning::SetVersionAndSettings(cbProject& Project, bool update)
 
465
{
 
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);
 
470
 
 
471
    VersionEditorDialog.SetCurrentProject(Project.GetTitle());
 
472
 
 
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);
 
478
 
 
479
    VersionEditorDialog.SetAuto(GetConfig().Settings.Autoincrement);
 
480
    VersionEditorDialog.SetDates(GetConfig().Settings.DateDeclarations);
 
481
 
 
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()));
 
488
 
 
489
    VersionEditorDialog.SetStatus(cbC2U(GetVersionState().Status.SoftwareStatus.c_str()));
 
490
    VersionEditorDialog.SetStatusAbbreviation(cbC2U(GetVersionState().Status.Abbreviation.c_str()));
 
491
 
 
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);
 
497
 
 
498
    VersionEditorDialog.SetChanges(GetConfig().ChangesLog.ShowChangesEditor);
 
499
    VersionEditorDialog.SetChangesTitle(cbC2U(GetConfig().ChangesLog.AppTitle.c_str()));
 
500
    VersionEditorDialog.SetChangesLogPath(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()));
 
501
 
 
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()));
 
505
 
 
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());
 
528
 
 
529
    //Save Header path
 
530
    m_versionHeaderPath = cbC2U(GetConfig().Settings.HeaderPath.c_str());
 
531
 
 
532
    if(OldConfig != GetConfig())
 
533
    {   // settings have changed => Project is to be considered changed
 
534
        Project.SetModified(true);
 
535
    }
 
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();
511
 
 
512
 
    GetVersionState().Status.SoftwareStatus = cbU2C(VersionEditorDialog.GetStatus());
513
 
    GetVersionState().Status.Abbreviation = cbU2C(VersionEditorDialog.GetStatusAbbreviation());
514
 
 
515
 
    if (!update)
516
 
    {   // first time; we just activated the plug-in on the project; clean start
517
 
        GetVersionState().BuildHistory = 0;
518
 
        m_Modified = false;
519
 
    }
520
 
    m_timerStatus->Start(1000);
521
 
}
 
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();
 
544
 
 
545
    GetVersionState().Status.SoftwareStatus = cbU2C(VersionEditorDialog.GetStatus());
 
546
    GetVersionState().Status.Abbreviation = cbU2C(VersionEditorDialog.GetStatusAbbreviation());
 
547
 
 
548
    if (!update)
 
549
    {   // first time; we just activated the plug-in on the project; clean start
 
550
        GetVersionState().BuildHistory = 0;
 
551
        m_Modified = false;
 
552
    }
 
553
    m_timerStatus->Start(1000);
 
554
}
522
555
 
523
556
/*
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
526
 
*/
527
 
void AutoVersioning::UpdateVersionHeader()
528
 
{
529
 
    m_timerStatus->Stop();
530
 
 
531
 
    wxString headerOutput = _T("");
532
 
    headerOutput << _T("#ifndef VERSION_H") << _T("\n");
533
 
    headerOutput << _T("#define VERSION_H") << _T("\n");
534
 
    headerOutput << _T("\n");
535
 
 
536
 
    if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
537
 
    {
538
 
        headerOutput << _T("namespace AutoVersion{") << _T("\n");
539
 
        headerOutput << _T("\t") << _T("\n");
540
 
    }
541
 
 
542
 
    if(GetConfig().Settings.DateDeclarations)
543
 
    {
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);
551
 
        wxString ubuntuYear;
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");
555
 
    }
556
 
 
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");
561
 
 
562
 
    wxString myPrintf;
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");
573
 
 
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");
577
 
 
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");
581
 
 
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");
585
 
 
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");
589
 
 
590
 
    if(GetConfig().Settings.Svn)
591
 
    {
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");
599
 
    }
600
 
 
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");
605
 
 
606
 
    headerOutput << _T("\t") << _T("\n\n");
607
 
 
608
 
    if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
609
 
    {
610
 
        headerOutput << _T("}") << _T("\n");
611
 
    }
612
 
 
613
 
    headerOutput << _T("#endif //VERSION_h\n");
614
 
 
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();
619
 
 
620
 
    m_timerStatus->Start(1000);
621
 
}
622
 
 
623
 
void AutoVersioning::CommitChanges()
624
 
{
625
 
    if (m_Project && IsAttached() && m_IsCurrentProjectVersioned)
626
 
    {
627
 
        if (m_Modified)
628
 
        {
629
 
            srand((unsigned)time(0));
630
 
            GetVersionState().Values.Revision += 1 + rand( ) % GetConfig().Scheme.RevisionRandMax;
631
 
 
632
 
            if ((GetConfig().Scheme.RevisionMax != 0) && (GetVersionState().Values.Revision > GetConfig().Scheme.RevisionMax))
633
 
            {
634
 
                GetVersionState().Values.Revision = 0;
635
 
            }
636
 
 
637
 
            if (GetConfig().Scheme.BuildMax == 0)
638
 
            {
639
 
                ++GetVersionState().Values.Build;
640
 
            }
641
 
            else if(GetVersionState().Values.Build >= GetConfig().Scheme.BuildMax)
642
 
            {
643
 
                GetVersionState().Values.Build = 0;
644
 
            }
645
 
            else
646
 
            {
647
 
                ++GetVersionState().Values.Build;
648
 
            }
649
 
            if(GetConfig().Settings.Autoincrement)
650
 
            {
651
 
                ++GetVersionState().BuildHistory;
652
 
                if(GetVersionState().BuildHistory >= GetConfig().Scheme.BuildTimesToIncrementMinor)
653
 
                {
654
 
                    GetVersionState().BuildHistory = 0;
655
 
                    ++GetVersionState().Values.Minor;
656
 
                }
657
 
                if (GetVersionState().Values.Minor > GetConfig().Scheme.MinorMax)
658
 
                {
659
 
                    GetVersionState().Values.Minor = 0;
660
 
                    ++GetVersionState().Values.Major;
661
 
                }
662
 
            }
663
 
            if(GetConfig().ChangesLog.ShowChangesEditor)
 
558
    just after SetVersionAndSettings() has shown the GUI to enter plugin configuration settings and version state variables
 
559
*/
 
560
void AutoVersioning::UpdateVersionHeader()
 
561
{
 
562
    m_timerStatus->Stop();
 
563
 
 
564
    //Declares the header guard to be used based on the filename
 
565
    wxFileName filename(cbC2U(GetConfig().Settings.HeaderPath.c_str()));
 
566
    wxString headerGuard;
 
567
 
 
568
    if(cbC2U(GetConfig().Code.HeaderGuard.c_str()) == _T(""))
 
569
    {
 
570
        headerGuard = filename.GetName() + _T("_") + filename.GetExt();
 
571
        headerGuard.Replace(_T(" "), _T("_"), true);
 
572
        headerGuard.UpperCase();
 
573
    }
 
574
    else
 
575
    {
 
576
        headerGuard = cbC2U(GetConfig().Code.HeaderGuard.c_str());
 
577
    }
 
578
 
 
579
    wxString prefix = cbC2U(GetConfig().Code.Prefix.c_str());
 
580
 
 
581
    if(prefix != _T(""))
 
582
    {
 
583
        prefix = prefix + _T("_");
 
584
    }
 
585
 
 
586
    wxString headerOutput = _T("");
 
587
    headerOutput << _T("#ifndef ") << headerGuard << _T("\n");
 
588
    headerOutput << _T("#define ") << headerGuard  << _T("\n");
 
589
    headerOutput << _T("\n");
 
590
 
 
591
    if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
 
592
    {
 
593
        headerOutput << _T("namespace ") << cbC2U(GetConfig().Code.NameSpace.c_str()) << _T("{") << _T("\n");
 
594
        headerOutput << _T("\t") << _T("\n");
 
595
    }
 
596
 
 
597
    if(GetConfig().Settings.DateDeclarations)
 
598
    {
 
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);
 
606
        wxString ubuntuYear;
 
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");
 
610
    }
 
611
 
 
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");
 
616
 
 
617
    wxString myPrintf;
 
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");
 
628
 
 
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");
 
632
 
 
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");
 
636
 
 
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");
 
640
 
 
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");
 
644
 
 
645
    if(GetConfig().Settings.Svn)
 
646
    {
 
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");
 
654
    }
 
655
 
 
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");
 
660
 
 
661
    headerOutput << _T("\t") << _T("\n\n");
 
662
 
 
663
    if(cbC2U(GetConfig().Settings.Language.c_str()) == _T("C++"))
 
664
    {
 
665
        headerOutput << _T("}") << _T("\n");
 
666
    }
 
667
 
 
668
    headerOutput << _T("#endif //") << headerGuard << _T("\n");
 
669
 
 
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();
 
674
 
 
675
    m_timerStatus->Start(1000);
 
676
}
 
677
 
 
678
void AutoVersioning::CommitChanges()
 
679
{
 
680
    if (m_Project && IsAttached() && m_IsVersioned[m_Project])
 
681
    {
 
682
        if (m_Modified)
 
683
        {
 
684
            srand((unsigned)time(0));
 
685
            GetVersionState().Values.Revision += 1 + rand( ) % GetConfig().Scheme.RevisionRandMax;
 
686
 
 
687
            if ((GetConfig().Scheme.RevisionMax != 0) && (GetVersionState().Values.Revision > GetConfig().Scheme.RevisionMax))
 
688
            {
 
689
                GetVersionState().Values.Revision = 0;
 
690
            }
 
691
 
 
692
            if (GetConfig().Scheme.BuildMax == 0)
 
693
            {
 
694
                ++GetVersionState().Values.Build;
 
695
            }
 
696
            else if(GetVersionState().Values.Build >= GetConfig().Scheme.BuildMax)
 
697
            {
 
698
                GetVersionState().Values.Build = 0;
 
699
            }
 
700
            else
 
701
            {
 
702
                ++GetVersionState().Values.Build;
 
703
            }
 
704
            if(GetConfig().Settings.Autoincrement)
 
705
            {
 
706
                ++GetVersionState().BuildHistory;
 
707
                if(GetVersionState().BuildHistory >= GetConfig().Scheme.BuildTimesToIncrementMinor)
 
708
                {
 
709
                    GetVersionState().BuildHistory = 0;
 
710
                    ++GetVersionState().Values.Minor;
 
711
                }
 
712
                if (GetVersionState().Values.Minor > GetConfig().Scheme.MinorMax)
 
713
                {
 
714
                    GetVersionState().Values.Minor = 0;
 
715
                    ++GetVersionState().Values.Major;
 
716
                }
 
717
            }
 
718
            if(GetConfig().ChangesLog.ShowChangesEditor)
664
719
            {
665
720
                GenerateChanges();
666
721
            }
667
722
            m_Project->SaveAllFiles();
668
 
 
669
 
            m_Modified = false;
 
723
 
 
724
            m_Modified = false;
670
725
            UpdateVersionHeader();
671
 
        }
672
 
    }
673
 
}
674
 
 
675
 
void AutoVersioning::GenerateChanges()
676
 
{
677
 
    avChangesDlg changesDlg((wxWindow*) Manager::Get()->GetAppWindow(),0L);
678
 
    changesDlg.SetTemporaryChangesFile(m_Project->GetBasePath() + _T("changes.tmp"));
679
 
    changesDlg.ShowModal();
680
 
 
681
 
    wxString changes = changesDlg.Changes();
682
 
 
683
 
    if (!changes.IsEmpty())
684
 
    {
685
 
        changes.Prepend(_T("        -"));
686
 
        changes.Replace(_T("\n"), _T("\n        -"));
687
 
 
688
 
        wxDateTime actualDate = wxDateTime::Now();
 
726
        }
 
727
    }
 
728
}
 
729
 
 
730
void AutoVersioning::GenerateChanges()
 
731
{
 
732
    avChangesDlg changesDlg((wxWindow*) Manager::Get()->GetAppWindow(),0L);
 
733
    changesDlg.SetTemporaryChangesFile(m_Project->GetBasePath() + _T("changes.tmp"));
 
734
    changesDlg.ShowModal();
 
735
 
 
736
    wxString changes = changesDlg.Changes();
 
737
 
 
738
    if (!changes.IsEmpty())
 
739
    {
 
740
        changes.Prepend(_T("        -"));
 
741
        changes.Replace(_T("\n"), _T("\n        -"));
 
742
 
 
743
        wxDateTime actualDate = wxDateTime::Now();
689
744
        wxString changesTitle = cbC2U(GetConfig().ChangesLog.AppTitle.c_str());
690
 
 
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")));
694
 
 
 
745
 
 
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")));
 
749
 
695
750
        wxString value;
696
 
        value.Printf(_T("%d"), GetVersionState().Values.Major);
697
 
        changesTitle.Replace(_T("%M"), value);
698
 
 
699
 
        value.Printf(_T("%d"), GetVersionState().Values.Minor);
700
 
        changesTitle.Replace(_T("%m"), value);
701
 
 
702
 
        value.Printf(_T("%d"), GetVersionState().Values.Build);
703
 
        changesTitle.Replace(_T("%b"), value);
704
 
 
705
 
        value.Printf(_T("%d"), GetVersionState().Values.Revision);
706
 
        changesTitle.Replace(_T("%r"), value);
707
 
 
708
 
        value.Printf(_T("%d"), GetConfig().Settings.Svn?1:0);
709
 
        changesTitle.Replace(_T("%s"),value);
710
 
 
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());
714
 
 
715
 
        wxString changesFile = FileNormalize(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()), m_Project->GetBasePath());
716
 
        wxString changesCurrentContent;
717
 
        if (wxFile::Exists(changesFile))
718
 
        {
719
 
            wxFFile file;
720
 
 
721
 
            file.Open(changesFile);
722
 
            file.ReadAll(&changesCurrentContent);
723
 
            file.Close();
724
 
        }
725
 
 
726
 
        wxString changesOutput = _T("");
727
 
 
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;
733
 
 
734
 
        wxFile file;
735
 
        file.Open(changesFile,wxFile::write);
736
 
        file.Write(changesOutput);
737
 
        file.Close();
738
 
 
739
 
    }//If not changes.IsEmpty()
740
 
}
741
 
 
742
 
wxString AutoVersioning::FileNormalize(const wxString& relativeFile, const wxString& workingDirectory)
743
 
{
744
 
    wxFileName fileNormalize(relativeFile);
745
 
    if(fileNormalize.Normalize(wxPATH_NORM_ABSOLUTE,workingDirectory))
746
 
    {
747
 
        //If everything is ok returns absolute path
748
 
        return fileNormalize.GetFullPath();
749
 
    }
750
 
    else
751
 
    {
752
 
        //If something goes wrong return project's cwd and filename with extension.
753
 
        return workingDirectory + fileNormalize.GetName() + fileNormalize.GetExt();
754
 
    }
755
 
}
 
751
        value.Printf(_T("%ld"), GetVersionState().Values.Major);
 
752
        changesTitle.Replace(_T("%M"), value);
 
753
 
 
754
        value.Printf(_T("%ld"), GetVersionState().Values.Minor);
 
755
        changesTitle.Replace(_T("%m"), value);
 
756
 
 
757
        value.Printf(_T("%ld"), GetVersionState().Values.Build);
 
758
        changesTitle.Replace(_T("%b"), value);
 
759
 
 
760
        value.Printf(_T("%ld"), GetVersionState().Values.Revision);
 
761
        changesTitle.Replace(_T("%r"), value);
 
762
 
 
763
        value.Printf(_T("%d"), GetConfig().Settings.Svn?1:0);
 
764
        changesTitle.Replace(_T("%s"),value);
 
765
 
 
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());
 
769
 
 
770
        wxString changesFile = FileNormalize(cbC2U(GetConfig().ChangesLog.ChangesLogPath.c_str()), m_Project->GetBasePath());
 
771
        wxString changesCurrentContent;
 
772
        if (wxFile::Exists(changesFile))
 
773
        {
 
774
            wxFFile file;
 
775
 
 
776
            file.Open(changesFile);
 
777
            file.ReadAll(&changesCurrentContent);
 
778
            file.Close();
 
779
        }
 
780
 
 
781
        wxString changesOutput = _T("");
 
782
 
 
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;
 
788
 
 
789
        wxFile file;
 
790
        file.Open(changesFile,wxFile::write);
 
791
        file.Write(changesOutput);
 
792
        file.Close();
 
793
 
 
794
    }//If not changes.IsEmpty()
 
795
}
 
796
 
 
797
wxString AutoVersioning::FileNormalize(const wxString& relativeFile, const wxString& workingDirectory)
 
798
{
 
799
    wxFileName fileNormalize(relativeFile);
 
800
    if(fileNormalize.Normalize(wxPATH_NORM_ABSOLUTE,workingDirectory))
 
801
    {
 
802
        //If everything is ok returns absolute path
 
803
        return fileNormalize.GetFullPath();
 
804
    }
 
805
    else
 
806
    {
 
807
        //If something goes wrong return project's cwd and filename with extension.
 
808
        return workingDirectory + fileNormalize.GetName() + fileNormalize.GetExt();
 
809
    }
 
810
}
756
811
 
757
812
avConfig& AutoVersioning::GetConfig()
758
813
{
764
819
    return m_ProjectMapVersionState[m_Project];
765
820
} // end of GetVersionState
766
821
 
767
 
//}
 
822
//}