Skip to content

Commit

Permalink
Startup wizard: fetch the compilers suggestion list to install from t…
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed Jul 27, 2015
1 parent 8fb5479 commit c2ac0f9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 32 deletions.
4 changes: 2 additions & 2 deletions LiteEditor.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<Project Name="wxsqlite3" ConfigName="Win_x86_Release"/>
<Project Name="ZoomNavigator" ConfigName="Win_x86_Release"/>
</WorkspaceConfiguration>
<WorkspaceConfiguration Name="CMake_Release" Selected="yes">
<WorkspaceConfiguration Name="CMake_Release" Selected="no">
<Project Name="ZoomNavigator" ConfigName="DebugUnicode"/>
<Project Name="wxsqlite3" ConfigName="Win_x86_Release"/>
<Project Name="wxshapeframework" ConfigName="Win_x86_Release"/>
Expand Down Expand Up @@ -279,7 +279,7 @@
<Project Name="WebTools" ConfigName="DebugUnicode"/>
<Project Name="HelpPlugin" ConfigName="Win_x64_Debug"/>
</WorkspaceConfiguration>
<WorkspaceConfiguration Name="Win_x64_Release" Selected="no">
<WorkspaceConfiguration Name="Win_x64_Release" Selected="yes">
<Project Name="abbreviation" ConfigName="Win_x64_Release"/>
<Project Name="CallGraph" ConfigName="Win_x64_Release"/>
<Project Name="CMakePlugin" ConfigName="Win_x64_Release"/>
Expand Down
86 changes: 59 additions & 27 deletions Plugin/CompilersDetectorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
#include <wx/choicdlg.h>
#include "includepathlocator.h"
#include "build_settings_config.h"
#include "json_node.h"
#include <wx/stream.h>
#include <wx/url.h>

CompilersDetectorManager::CompilersDetectorManager()
{
Expand Down Expand Up @@ -109,6 +112,7 @@ bool CompilersDetectorManager::FoundMinGWCompiler() const
return false;
}

#define DLBUFSIZE 1024
void CompilersDetectorManager::MSWSuggestToDownloadMinGW(bool prompt)
{
#ifdef __WXMSW__
Expand All @@ -120,36 +124,64 @@ void CompilersDetectorManager::MSWSuggestToDownloadMinGW(bool prompt)
// No MinGW compiler detected!, offer the user to download one
wxStringMap_t mingwCompilers;
wxArrayString options;
mingwCompilers.insert(std::make_pair(
"MinGW 5.1.0 - 32 Bit",
"http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm-gcc-5.1.0-3.exe/download"));
mingwCompilers.insert(std::make_pair(
"MinGW 5.1.0 - 64 Bit",
"http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe/download"));
wxStringMap_t::iterator iter = mingwCompilers.begin();
for(; iter != mingwCompilers.end(); ++iter) {
options.Add(iter->first);
}

#ifdef _WIN64
int sel = 1;
#else
int sel = 0;
#endif
wxString selection =
::wxGetSingleChoice(_("Select a compiler to download"), _("Choose compiler"), options, sel);
if(!selection.IsEmpty()) {
// Reset the compiler detection flag so next time codelite is restarted, it will
// rescan the machine
clConfig::Get().Write(kConfigBootstrapCompleted, false);

// Open the browser to start downloading the compiler
::wxLaunchDefaultBrowser(mingwCompilers.find(selection)->second);
::wxMessageBox(_("After install is completed, click the 'Scan' button"),
"CodeLite",
wxOK | wxCENTER | wxICON_INFORMATION);
// Load the compilers list from the website
wxURL url("http://codelite.org/compilers.json");

if(url.GetError() == wxURL_NOERR) {

wxInputStream* in_stream = url.GetInputStream();
if(!in_stream) {
return;
}
unsigned char buffer[DLBUFSIZE + 1];
wxString dataRead;
do {
in_stream->Read(buffer, DLBUFSIZE);
size_t bytes_read = in_stream->LastRead();
if(bytes_read > 0) {
buffer[bytes_read] = 0;
wxString buffRead((const char*)buffer, wxConvUTF8);
dataRead.Append(buffRead);
}

} while(!in_stream->Eof());

JSONRoot root(dataRead);
JSONElement compilers = root.toElement().namedObject("Compilers");
JSONElement arr = compilers.namedObject("MinGW");
int count = arr.arraySize();
for(int i = 0; i < count; ++i) {
JSONElement compiler = arr.arrayItem(i);
mingwCompilers.insert(
std::make_pair(compiler.namedObject("Name").toString(), compiler.namedObject("URL").toString()));
options.Add(compiler.namedObject("Name").toString());
}

if(options.IsEmpty()) {
::wxMessageBox(_("Unable to fetch compilers list from the website\nhttp://codelite.org/compilers.json"),
"CodeLite",
wxOK | wxCENTER | wxICON_WARNING);
return;
}
int sel = 0;

wxString selection =
::wxGetSingleChoice(_("Select a compiler to download"), _("Choose compiler"), options, sel);
if(!selection.IsEmpty()) {
// Reset the compiler detection flag so next time codelite is restarted, it will
// rescan the machine
clConfig::Get().Write(kConfigBootstrapCompleted, false);

// Open the browser to start downloading the compiler
::wxLaunchDefaultBrowser(mingwCompilers.find(selection)->second);
::wxMessageBox(_("After install is completed, click the 'Scan' button"),
"CodeLite",
wxOK | wxCENTER | wxICON_INFORMATION);
}
}
}

#endif // __WXMSW__
}

Expand Down
3 changes: 0 additions & 3 deletions TODO.TXT
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
MUST:
=====

* Fixed assertion in debug
* Move the compilers links to a JSON file that can be downloaded from CodeLite's website

NICE
====

Expand Down
13 changes: 13 additions & 0 deletions compilers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Compilers" : {
"MinGW" : [
{
"Name" : "MinGW-TDM 5.1/32 bit",
"URL" : "http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm-gcc-5.1.0-3.exe/download"
} , {
"Name" : "MinGW-TDM 5.1/64 bit",
"URL" : "http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe/download"
}
]
}
}

0 comments on commit c2ac0f9

Please sign in to comment.