~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

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

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

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: 8680 $
 
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 $
 
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: // fall-through
 
61
        default:
 
62
            return false;
 
63
    }
 
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))
 
68
    {
 
69
        case wxID_YES:
 
70
            askForTargets = false; break;
 
71
        case wxID_NO:
 
72
            askForTargets = true; break;
 
73
        case wxID_CANCEL: // fall-through
 
74
        default:
 
75
            return false;
 
76
    }
 
77
 
 
78
    wxFileInputStream file(filename);
 
79
    if (!file.Ok())
 
80
        return false; // error opening file???
 
81
 
 
82
    wxArrayString comps;
 
83
    wxTextInputStream input(file);
 
84
 
 
85
    // read "header"
 
86
    if (!file.Eof())
 
87
    {
 
88
        wxString line = input.ReadLine();
 
89
        if (line.IsEmpty())
 
90
        {
 
91
            Manager::Get()->GetLogManager()->DebugLog(_T("Workspace file has unsupported format."));
 
92
            return false;
 
93
        }
 
94
        comps = GetArrayFromString(line, _T(","));
 
95
        line = comps[0];
 
96
        line.Trim(true);
 
97
        line.Trim(false);
 
98
        if (line != _T("Microsoft Developer Studio Workspace File"))
 
99
        {
 
100
            Manager::Get()->GetLogManager()->DebugLog(_T("Workspace file has unsupported format."));
 
101
            return false;
 
102
        }
 
103
        line = comps.GetCount() > 1 ? comps[1] : wxString(wxEmptyString);
 
104
        line.Trim(true);
 
105
        line.Trim(false);
 
106
 
 
107
        if (line != _T("Format Version 6.00"))
 
108
            Manager::Get()->GetLogManager()->DebugLog(_T("Workspace format not recognized. Will try to parse though..."));
 
109
    }
 
110
 
 
111
    ImportersGlobals::UseDefaultCompiler = !askForCompiler;
 
112
    ImportersGlobals::ImportAllTargets = !askForTargets;
 
113
 
 
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);
 
117
 
 
118
    int count = 0;
 
119
    cbProject* project = 0;
 
120
    cbProject* firstproject = 0;
 
121
    wxFileName wfname = filename;
 
122
    wfname.Normalize();
 
123
    Manager::Get()->GetLogManager()->DebugLog(_T("Workspace dir: ") + wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
 
124
 
 
125
    while (!file.Eof())
 
126
    {
 
127
        wxString line = input.ReadLine();
 
128
 
 
129
        line.Trim(true);
 
130
        line.Trim(false);
 
131
 
 
132
        // example wanted line:
 
133
        //Project: "Demo_BSP"=.\Samples\BSP\scripts\Demo_BSP.dsp - Package Owner=<4>
 
134
        if (line.StartsWith(_T("Project:")))
 
135
        {
 
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
 
142
 
 
143
            if (equal == -1 || minus == -1)
 
144
            {
 
145
                Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (unrecognised format) in workspace file."));
 
146
                continue;
 
147
            }
 
148
 
 
149
            // read project title and trim quotes
 
150
            wxString prjTitle = line.Left(equal);
 
151
            prjTitle.Trim(true);
 
152
            prjTitle.Trim(false);
 
153
            if (prjTitle.IsEmpty())
 
154
            {
 
155
                Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (empty name) in workspace file."));
 
156
                continue;
 
157
            }
 
158
            if (prjTitle.GetChar(0) == _T('\"'))
 
159
            {
 
160
                prjTitle.Truncate(prjTitle.Length() - 1);
 
161
                prjTitle.Remove(0, 1);
 
162
            }
 
163
 
 
164
            // read project filename and trim quotes
 
165
            ++equal;
 
166
            wxString prjFile = line.Mid(equal, minus - equal);
 
167
            prjFile.Trim(true);
 
168
            prjFile.Trim(false);
 
169
 
 
170
            if (prjFile.IsEmpty())
 
171
            {
 
172
                Manager::Get()->GetLogManager()->DebugLog(_T("Skipping invalid project (empty file) in workspace file."));
 
173
                continue;
 
174
            }
 
175
 
 
176
            if (prjFile.GetChar(0) == _T('\"'))
 
177
            {
 
178
                prjFile.Truncate(prjFile.Length() - 1);
 
179
                prjFile.Remove(0, 1);
 
180
            }
 
181
 
 
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())
 
185
            {
 
186
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Project '%s' from '%s' not found."), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
 
187
                continue;
 
188
            }
 
189
            Manager::Get()->GetLogManager()->DebugLog(F(_T("Found project '%s' in '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
 
190
 
 
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))
 
194
                break;
 
195
 
 
196
            project = Manager::Get()->GetProjectManager()->LoadProject(fname.GetFullPath(), false);
 
197
            if (!firstproject)
 
198
                firstproject = project;
 
199
 
 
200
            if (!project)
 
201
                Manager::Get()->GetLogManager()->Log(F(_("Warning: Unable to load project '%s' from '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
 
202
            else
 
203
            {
 
204
                Manager::Get()->GetLogManager()->Log(F(_("Registering project '%s' from '%s'"), prjTitle.wx_str(), fname.GetFullPath().wx_str()));
 
205
                registerProject(project->GetTitle(), project);
 
206
                ++count;
 
207
            }
 
208
        }
 
209
        /*
 
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
 
214
         */
 
215
        else if (line.StartsWith(_T("Project_Dep_Name")))
 
216
        {
 
217
            line.Remove(0, 16);
 
218
            line.Trim(false);
 
219
            if (project) addDependency(project->GetTitle(), line);
 
220
        }
 
221
    }
 
222
 
 
223
    if (firstproject)
 
224
        Manager::Get()->GetProjectManager()->SetProject(firstproject);
 
225
 
 
226
    updateProjects();
 
227
    ImportersGlobals::ResetDefaults();
 
228
 
 
229
    Title = wxFileName(filename).GetName() + _(" workspace");
 
230
    return count != 0;
 
231
}
 
232
 
 
233
bool MSVCWorkspaceLoader::Save(cb_unused const wxString& title, cb_unused const wxString& filename)
 
234
{
 
235
    // no support for saving workspace files (.dsw)
 
236
    return false;
 
237
}