2
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3
* http://www.gnu.org/licenses/gpl-3.0.html
6
* $Id: msvcworkspaceloader.cpp 8680 2012-12-16 14:58:35Z mortenmacfly $
7
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/plugins/projectsimporter/msvcworkspaceloader.cpp $
13
#include <wx/string.h>
15
#include <wx/txtstrm.h>
16
#include <wx/dynarray.h>
17
#include <wx/filename.h>
18
#include <wx/msgdlg.h>
19
#include <wx/wfstream.h>
23
#include "logmanager.h"
24
#include "projectmanager.h"
25
#include "compilerfactory.h"
27
#include "cbproject.h"
30
#include <wx/stream.h>
31
#include <wx/progdlg.h>
33
#include "msvcworkspaceloader.h"
34
#include "importers_globals.h"
36
MSVCWorkspaceLoader::MSVCWorkspaceLoader()
41
MSVCWorkspaceLoader::~MSVCWorkspaceLoader()
46
bool MSVCWorkspaceLoader::Open(const wxString& filename, wxString& Title)
48
bool askForCompiler = false;
49
bool askForTargets = false;
50
switch (cbMessageBox(_("Do you want the imported projects to use the default compiler?\n"
51
"(If you answer No, you will be asked for each and every project"
52
" which compiler to use...)"), _("Question"), wxICON_QUESTION | wxYES_NO | wxCANCEL))
55
askForCompiler = false;
58
askForCompiler = true;
60
case wxID_CANCEL: // fall-through
64
switch (cbMessageBox(_("Do you want to import all configurations (e.g. Debug/Release) from the "
65
"imported projects?\n"
66
"(If you answer No, you will be asked for each and every project"
67
" which configurations to import...)"), _("Question"), wxICON_QUESTION | wxYES_NO | wxCANCEL))
70
askForTargets = false; break;
72
askForTargets = true; break;
73
case wxID_CANCEL: // fall-through
78
wxFileInputStream file(filename);
80
return false; // error opening file???
83
wxTextInputStream input(file);
88
wxString line = input.ReadLine();
91
Manager::Get()->GetLogManager()->DebugLog(_T("Workspace file has unsupported format."));
94
comps = GetArrayFromString(line, _T(","));
98
if (line != _T("Microsoft Developer Studio Workspace File"))
100
Manager::Get()->GetLogManager()->DebugLog(_T("Workspace file has unsupported format."));
103
line = comps.GetCount() > 1 ? comps[1] : wxString(wxEmptyString);
107
if (line != _T("Format Version 6.00"))
108
Manager::Get()->GetLogManager()->DebugLog(_T("Workspace format not recognized. Will try to parse though..."));
111
ImportersGlobals::UseDefaultCompiler = !askForCompiler;
112
ImportersGlobals::ImportAllTargets = !askForTargets;
114
wxProgressDialog progress(_("Importing MSVC 6 workspace"),
115
_("Please wait while importing MSVC 6 workspace..."),
116
100, 0, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
119
cbProject* project = 0;
120
cbProject* firstproject = 0;
121
wxFileName wfname = filename;
123
Manager::Get()->GetLogManager()->DebugLog(_T("Workspace dir: ") + wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
127
wxString line = input.ReadLine();
132
// example wanted line:
133
//Project: "Demo_BSP"=.\Samples\BSP\scripts\Demo_BSP.dsp - Package Owner=<4>
134
if (line.StartsWith(_T("Project:")))
136
line.Remove(0, 8); // remove "Project:"
137
// now we need to find the equal sign (=) that separates the
138
// project title from the filename, and the minus sign (-)
139
// that separates the filename from junk info - at least to this importer ;)
140
int equal = line.Find(_T('='));
141
int minus = line.Find(_T('-'), true); // search from end
143
if (equal == -1 || minus == -1)
145
Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (unrecognised format) in workspace file."));
149
// read project title and trim quotes
150
wxString prjTitle = line.Left(equal);
152
prjTitle.Trim(false);
153
if (prjTitle.IsEmpty())
155
Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (empty name) in workspace file."));
158
if (prjTitle.GetChar(0) == _T('\"'))
160
prjTitle.Truncate(prjTitle.Length() - 1);
161
prjTitle.Remove(0, 1);
164
// read project filename and trim quotes
166
wxString prjFile = line.Mid(equal, minus - equal);
170
if (prjFile.IsEmpty())
172
Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (empty file) in workspace file."));
176
if (prjFile.GetChar(0) == _T('\"'))
178
prjFile.Truncate(prjFile.Length() - 1);
179
prjFile.Remove(0, 1);
182
wxFileName fname(UnixFilename(prjFile));
183
fname.Normalize(wxPATH_NORM_ALL, wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR), wxPATH_NATIVE);
184
if (!fname.FileExists())
186
Manager::Get()->GetLogManager()->DebugLog(F(_T("Project '%s' from '%s' not found."), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
189
Manager::Get()->GetLogManager()->DebugLog(F(_T("Found project '%s' in '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
191
int percentage = ((int)file.TellI())*100 / (int)(file.GetLength());
192
// While updating the progrerss dialog check for cancellation - probably interrupt.
193
if (!progress.Update(percentage, _("Importing project: ") + prjTitle))
196
project = Manager::Get()->GetProjectManager()->LoadProject(fname.GetFullPath(), false);
198
firstproject = project;
201
Manager::Get()->GetLogManager()->Log(F(_("Warning: Unable to load project '%s' from '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
204
Manager::Get()->GetLogManager()->Log(F(_("Registering project '%s' from '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
205
registerProject(project->GetTitle(), project);
210
* example wanted line:
211
* Project_Dep_Name VstSDK
212
* and add the dependency/link of the VstSDK project to the current project
213
* be carefull, the dependent projects could not have already been read, so we have to remember them
215
else if (line.StartsWith(_T("Project_Dep_Name")))
219
if (project) addDependency(project->GetTitle(), line);
224
Manager::Get()->GetProjectManager()->SetProject(firstproject);
227
ImportersGlobals::ResetDefaults();
229
Title = wxFileName(filename).GetName() + _(" workspace");
233
bool MSVCWorkspaceLoader::Save(cb_unused const wxString& title, cb_unused const wxString& filename)
235
// no support for saving workspace files (.dsw)