~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/projectsimporter/msvcworkspaceloader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
4
 *
 
5
 * $Revision: 4909 $
 
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 $
 
8
 */
 
9
 
 
10
#include "sdk.h"
 
11
 
 
12
#ifndef CB_PRECOMP
 
13
    #include <wx/string.h>
 
14
    #include <wx/intl.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>
 
20
 
 
21
    #include "globals.h"
 
22
    #include "manager.h"
 
23
    #include "logmanager.h"
 
24
    #include "projectmanager.h"
 
25
    #include "compilerfactory.h"
 
26
    #include "compiler.h"
 
27
    #include "cbproject.h"
 
28
#endif
 
29
 
 
30
#include <wx/stream.h>
 
31
#include <wx/progdlg.h>
 
32
 
 
33
#include "msvcworkspaceloader.h"
 
34
#include "importers_globals.h"
 
35
 
 
36
MSVCWorkspaceLoader::MSVCWorkspaceLoader()
 
37
{
 
38
    //ctor
 
39
}
 
40
 
 
41
MSVCWorkspaceLoader::~MSVCWorkspaceLoader()
 
42
{
 
43
    //dtor
 
44
}
 
45
 
 
46
bool MSVCWorkspaceLoader::Open(const wxString& filename, wxString& Title)
 
47
{
 
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))
 
53
    {
 
54
        case wxID_YES:
 
55
            askForCompiler = false;
 
56
            break;
 
57
        case wxID_NO:
 
58
            askForCompiler = true;
 
59
            break;
 
60
        case wxID_CANCEL:
 
61
            return false;
 
62
    }
 
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))
 
67
    {
 
68
        case wxID_YES:
 
69
            askForTargets = false; break;
 
70
        case wxID_NO:
 
71
            askForTargets = true; break;
 
72
        case wxID_CANCEL:
 
73
            return false;
 
74
    }
 
75
 
 
76
    wxFileInputStream file(filename);
 
77
    if (!file.Ok())
 
78
        return false; // error opening file???
 
79
 
 
80
    wxArrayString comps;
 
81
    wxTextInputStream input(file);
 
82
 
 
83
    // read "header"
 
84
    if (!file.Eof())
 
85
    {
 
86
        wxString line = input.ReadLine();
 
87
        if (line.IsEmpty())
 
88
        {
 
89
            Manager::Get()->GetLogManager()->DebugLog(_T("Unsupported format."));
 
90
            return false;
 
91
        }
 
92
        comps = GetArrayFromString(line, _T(","));
 
93
        line = comps[0];
 
94
        line.Trim(true);
 
95
        line.Trim(false);
 
96
        if (line != _T("Microsoft Developer Studio Workspace File"))
 
97
        {
 
98
            Manager::Get()->GetLogManager()->DebugLog(_T("Unsupported format."));
 
99
            return false;
 
100
        }
 
101
        line = comps.GetCount() > 1 ? comps[1] : wxString(wxEmptyString);
 
102
        line.Trim(true);
 
103
        line.Trim(false);
 
104
        if (line != _T("Format Version 6.00"))
 
105
            Manager::Get()->GetLogManager()->DebugLog(_T("Format not recognized. Will try to parse though..."));
 
106
    }
 
107
 
 
108
    ImportersGlobals::UseDefaultCompiler = !askForCompiler;
 
109
    ImportersGlobals::ImportAllTargets = !askForTargets;
 
110
 
 
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);
 
114
 
 
115
    int count = 0;
 
116
    cbProject* project = 0;
 
117
    cbProject* firstproject = 0;
 
118
    wxFileName wfname = filename;
 
119
    wfname.Normalize();
 
120
    Manager::Get()->GetLogManager()->DebugLog(_T("Workspace dir: ") + wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
 
121
    while (!file.Eof())
 
122
    {
 
123
        wxString line = input.ReadLine();
 
124
 
 
125
        line.Trim(true);
 
126
        line.Trim(false);
 
127
 
 
128
        // example wanted line:
 
129
        //Project: "Demo_BSP"=.\Samples\BSP\scripts\Demo_BSP.dsp - Package Owner=<4>
 
130
        if (line.StartsWith(_T("Project:")))
 
131
        {
 
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
 
138
 
 
139
            if (equal == -1 || minus == -1)
 
140
                continue;
 
141
 
 
142
            // read project title and trim quotes
 
143
            wxString prjTitle = line.Left(equal);
 
144
            prjTitle.Trim(true);
 
145
            prjTitle.Trim(false);
 
146
            if (prjTitle.IsEmpty())
 
147
                continue;
 
148
            if (prjTitle.GetChar(0) == _T('\"'))
 
149
            {
 
150
                prjTitle.Truncate(prjTitle.Length() - 1);
 
151
                prjTitle.Remove(0, 1);
 
152
            }
 
153
 
 
154
            // read project filename and trim quotes
 
155
            ++equal;
 
156
            wxString prjFile = line.Mid(equal, minus - equal);
 
157
            prjFile.Trim(true);
 
158
            prjFile.Trim(false);
 
159
            if (prjFile.IsEmpty())
 
160
                continue;
 
161
            if (prjFile.GetChar(0) == _T('\"'))
 
162
            {
 
163
                prjFile.Truncate(prjFile.Length() - 1);
 
164
                prjFile.Remove(0, 1);
 
165
            }
 
166
 
 
167
            ++count;
 
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()));
 
171
 
 
172
            int percentage = ((int)file.TellI())*100 / (int)(file.GetLength());
 
173
            if (!progress.Update(percentage, _("Importing project: ") + prjTitle))
 
174
                break;
 
175
 
 
176
            project = Manager::Get()->GetProjectManager()->LoadProject(fname.GetFullPath(), false);
 
177
            if (!firstproject) firstproject = project;
 
178
            if (project) registerProject(project->GetTitle(), project);
 
179
        }
 
180
        /*
 
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
 
185
         */
 
186
        else if (line.StartsWith(_T("Project_Dep_Name")))
 
187
        {
 
188
            line.Remove(0, 16);
 
189
            line.Trim(false);
 
190
            if (project) addDependency(project->GetTitle(), line);
 
191
        }
 
192
    }
 
193
 
 
194
    if (firstproject)
 
195
        Manager::Get()->GetProjectManager()->SetProject(firstproject);
 
196
    updateProjects();
 
197
    ImportersGlobals::ResetDefaults();
 
198
 
 
199
    Title = wxFileName(filename).GetName() + _(" workspace");
 
200
    return count != 0;
 
201
}
 
202
 
 
203
bool MSVCWorkspaceLoader::Save(const wxString& /*title*/, const wxString& /*filename*/)
 
204
{
 
205
    // no support for saving workspace files (.dsw)
 
206
    return false;
 
207
}