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 4909 2008-02-27 13:15:26Z mortenmacfly $
7
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/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;
63
switch (cbMessageBox(_("Do you want to import all configurations (e.g. Debug/Release) from the "
64
"imported projects?\n"
65
"(If you answer No, you will be asked for each and every project"
66
" which configurations to import...)"), _("Question"), wxICON_QUESTION | wxYES_NO | wxCANCEL))
69
askForTargets = false; break;
71
askForTargets = true; break;
76
wxFileInputStream file(filename);
78
return false; // error opening file???
81
wxTextInputStream input(file);
86
wxString line = input.ReadLine();
89
Manager::Get()->GetLogManager()->DebugLog(_T("Unsupported format."));
92
comps = GetArrayFromString(line, _T(","));
96
if (line != _T("Microsoft Developer Studio Workspace File"))
98
Manager::Get()->GetLogManager()->DebugLog(_T("Unsupported format."));
101
line = comps.GetCount() > 1 ? comps[1] : wxString(wxEmptyString);
104
if (line != _T("Format Version 6.00"))
105
Manager::Get()->GetLogManager()->DebugLog(_T("Format not recognized. Will try to parse though..."));
108
ImportersGlobals::UseDefaultCompiler = !askForCompiler;
109
ImportersGlobals::ImportAllTargets = !askForTargets;
111
wxProgressDialog progress(_("Importing MSVC 6 workspace"),
112
_("Please wait while importing MSVC 6 workspace..."),
113
100, 0, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
116
cbProject* project = 0;
117
cbProject* firstproject = 0;
118
wxFileName wfname = filename;
120
Manager::Get()->GetLogManager()->DebugLog(_T("Workspace dir: ") + wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
123
wxString line = input.ReadLine();
128
// example wanted line:
129
//Project: "Demo_BSP"=.\Samples\BSP\scripts\Demo_BSP.dsp - Package Owner=<4>
130
if (line.StartsWith(_T("Project:")))
132
line.Remove(0, 8); // remove "Project:"
133
// now we need to find the equal sign (=) that separates the
134
// project title from the filename, and the minus sign (-)
135
// that separates the filename from junk info - at least to this importer ;)
136
int equal = line.Find(_T('='));
137
int minus = line.Find(_T('-'), true); // search from end
139
if (equal == -1 || minus == -1)
142
// read project title and trim quotes
143
wxString prjTitle = line.Left(equal);
145
prjTitle.Trim(false);
146
if (prjTitle.IsEmpty())
148
if (prjTitle.GetChar(0) == _T('\"'))
150
prjTitle.Truncate(prjTitle.Length() - 1);
151
prjTitle.Remove(0, 1);
154
// read project filename and trim quotes
156
wxString prjFile = line.Mid(equal, minus - equal);
159
if (prjFile.IsEmpty())
161
if (prjFile.GetChar(0) == _T('\"'))
163
prjFile.Truncate(prjFile.Length() - 1);
164
prjFile.Remove(0, 1);
168
wxFileName fname(UnixFilename(prjFile));
169
fname.Normalize(wxPATH_NORM_ALL, wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR), wxPATH_NATIVE);
170
Manager::Get()->GetLogManager()->DebugLog(F(_T("Found project '%s' in '%s'"), prjTitle.c_str(), fname.GetFullPath().c_str()));
172
int percentage = ((int)file.TellI())*100 / (int)(file.GetLength());
173
if (!progress.Update(percentage, _("Importing project: ") + prjTitle))
176
project = Manager::Get()->GetProjectManager()->LoadProject(fname.GetFullPath(), false);
177
if (!firstproject) firstproject = project;
178
if (project) registerProject(project->GetTitle(), project);
181
* example wanted line:
182
* Project_Dep_Name VstSDK
183
* and add the dependency/link of the VstSDK project to the current project
184
* be carefull, the dependent projects could not have already been read, so we have to remember them
186
else if (line.StartsWith(_T("Project_Dep_Name")))
190
if (project) addDependency(project->GetTitle(), line);
195
Manager::Get()->GetProjectManager()->SetProject(firstproject);
197
ImportersGlobals::ResetDefaults();
199
Title = wxFileName(filename).GetName() + _(" workspace");
203
bool MSVCWorkspaceLoader::Save(const wxString& /*title*/, const wxString& /*filename*/)
205
// no support for saving workspace files (.dsw)