Skip to content

Commit

Permalink
More Public Library work
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kinder committed Jul 2, 2014
1 parent cc50c82 commit e16e086
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 50 deletions.
86 changes: 72 additions & 14 deletions Inform7/ExtensionFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "TextFormat.h"
#include "NewDialogs.h"
#include "Dialogs.h"
#include "OSLayer.h"
#include "Build.h"

#ifdef _DEBUG
Expand Down Expand Up @@ -420,9 +421,13 @@ bool ExtensionFrame::InstallExtensions(CWnd* parent)
return false;

// Iterate over the selected extensions
CStringW lastExt;
int installed = 0, total = 0;
POSITION pos = dialog.GetStartPosition();
while (pos != NULL)
{
total++;

// Get the first line of the extension
CString path = dialog.GetNextPathName(pos);
CStringW extLine = ReadExtensionFirstLine(path);
Expand Down Expand Up @@ -474,13 +479,19 @@ bool ExtensionFrame::InstallExtensions(CWnd* parent)

// Copy the extension
if (::CopyFile(path,target,FALSE))
{
DeleteOldExtension(target);
lastExt.Format(L"\"%s\" by %s (%s)",(LPCWSTR)extName,(LPCWSTR)extAuthor,(LPCWSTR)extVersion);
installed++;
}
}

// Update the extensions menu and documentation
HANDLE process = theApp.RunCensus(true);
ShowInstalledMessage(parent,installed,total,lastExt);
theApp.FindExtensions();
theApp.SendAllFrames(InformApp::Extensions,0);
theApp.RunCensus(true);
theApp.WaitForProcessEnd(process);
return true;
}

Expand Down Expand Up @@ -581,18 +592,23 @@ void ExtensionFrame::DownloadExtensions(CFrameWnd* parent, CStringArray* urls)
{
{
CWaitCursor wc;
parent->SetMessageText("Downloading extensions");

int installed = 0;
for (int i = 0; i < urls->GetSize(); i++)
CStringW lastExt;
int installed = 0, total = urls->GetSize();
for (int i = 0; i < total; i++)
{
parent->SendMessage(WM_PROGRESS,
(int)(100 * ((double)i / (double)urls->GetSize())));
SetDownloadProgress(parent,total,i,installed);

CString url = urls->GetAt(i);
if (url.Left(8) != "library:")
continue;

// Get the ID of the download
int idIdx = url.Find("?id=");
if (idIdx <= 0)
continue;
int id = atoi(((LPCSTR)url)+idIdx+4);

// Determine the path for downloaded extension files
CString downPath;
::GetTempPath(MAX_PATH,downPath.GetBuffer(MAX_PATH));
Expand Down Expand Up @@ -630,6 +646,8 @@ void ExtensionFrame::DownloadExtensions(CFrameWnd* parent, CStringArray* urls)
if (::CopyFile(downPath,target,FALSE))
{
DeleteOldExtension(target);
theApp.SendAllFrames(InformApp::DownloadedExt,id);
lastExt.Format(L"\"%s\" by %s (%s)",(LPCWSTR)extName,(LPCWSTR)extAuthor,(LPCWSTR)extVersion);
installed++;
}
}
Expand All @@ -638,20 +656,17 @@ void ExtensionFrame::DownloadExtensions(CFrameWnd* parent, CStringArray* urls)
// Delete the downloaded file
::DeleteFile(downPath);
}
SetDownloadProgress(parent,total,total,installed);

parent->SendMessage(WM_PROGRESS,100);
CString msg;
msg.Format("Downloaded and installed %d extension%s",installed,(installed != 1) ? "s" : "");
parent->SetMessageText(msg);
msg.Format("Attempted to download %d extensions, %d failed.",urls->GetSize(),urls->GetSize()-installed);
parent->MessageBox(msg,INFORM_TITLE,MB_ICONINFORMATION|MB_OK);
// Notify the user of what happened
theApp.RunCensus(false);
ShowInstalledMessage(parent,installed,total,lastExt);
parent->SendMessage(WM_PROGRESS,-1);
}

// Update the extensions menu and documentation
// Update the extensions menu
theApp.FindExtensions();
theApp.SendAllFrames(InformApp::Extensions,0);
theApp.RunCensus(true);
}

CStringW ExtensionFrame::ReadExtensionFirstLine(const char* path)
Expand Down Expand Up @@ -804,6 +819,49 @@ void ExtensionFrame::DeleteOldExtension(CString path)
::DeleteFile(path);
}

void ExtensionFrame::SetDownloadProgress(CFrameWnd* parent, int total, int current, int installed)
{
parent->SendMessage(WM_PROGRESS,(int)(100 * ((double)current / (double)total)));

CString status;
status.Format("Installed %d of %d",installed,total);
if (current > installed)
status.AppendFormat(" (%d failed)",current-installed);
parent->SetMessageText(status);
}

void ExtensionFrame::ShowInstalledMessage(CWnd* parent, int installed, int total, LPCWSTR lastExt)
{
CStringW msg;
if (total > installed)
{
// One or more errors
if (installed > 0)
{
if (installed == 1)
msg.Format(L"One extension installed successfully, %d failed.",total-installed);
else
msg.Format(L"%d extensions installed successfully, %d failed.",installed,total-installed);
}
else
{
if (total > 1)
msg.Format(L"Failed to install %d extensions.",total);
else
msg = "Failed to install extension.";
}
}
else
{
// No errors
if (installed > 1)
msg.Format(L"Installation complete.\n\n%d extensions installed successfully.",installed);
else
msg.Format(L"Installation complete.\n\nExtension %s installed successfully.",lastExt);
}
theOS.MessageBox(parent,msg,L_INFORM_TITLE,MB_ICONINFORMATION|MB_OK);
}

CString ExtensionFrame::GetDisplayName(bool showEdited)
{
CString name = m_extension;
Expand Down
4 changes: 3 additions & 1 deletion Inform7/ExtensionFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class ExtensionFrame : public MenuBarFrameWnd
static ExtensionFrame* NewFrame(const ProjectSettings& settings);
static bool RemoveI7X(CString& path);
static void DeleteOldExtension(CString path);

static void SetDownloadProgress(CFrameWnd* parent, int total, int current, int installed);
static void ShowInstalledMessage(CWnd* parent, int installed, int total, LPCWSTR lastExt);

void OpenFile(const char* path);
void SetFromRegistryPath(const char* path);
bool IsProjectEdited(void);
Expand Down
36 changes: 23 additions & 13 deletions Inform7/Inform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,14 @@ void InformApp::RunMessagePump(void)
MSG msg;
while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if (PumpMessage() == FALSE)
if (msg.message == WM_COMMAND)
::PeekMessage(&msg,NULL,0,0,PM_REMOVE);
else if (PumpMessage() == FALSE)
exit(ExitInstance());
}

if (IsWaitCursor())
RestoreWaitCursor();
}

int InformApp::RunCommand(const char* dir, CString& command, OutputSink& output)
Expand Down Expand Up @@ -866,7 +871,7 @@ int InformApp::RunCommand(const char* dir, CString& command, OutputSink& output)
return result;
}

void InformApp::RunCensus(bool wait)
HANDLE InformApp::RunCensus(bool wait)
{
CString command, dir = GetAppDir();
command.Format("\"%s\\Compilers\\ni\" -rules \"%s\\Inform7\\Extensions\" -census",
Expand All @@ -886,20 +891,25 @@ void InformApp::RunCensus(bool wait)

if (created)
{
::CloseHandle(process.hThread);
if (wait)
{
DWORD result = STILL_ACTIVE;
while (result == STILL_ACTIVE)
{
::MsgWaitForMultipleObjects(0,NULL,FALSE,INFINITE,QS_ALLINPUT);
RunMessagePump();
::GetExitCodeProcess(process.hProcess,&result);
}
}
return process.hProcess;
else
::CloseHandle(process.hProcess);
}
return 0;
}

::CloseHandle(process.hProcess);
::CloseHandle(process.hThread);
void InformApp::WaitForProcessEnd(HANDLE process)
{
DWORD result = STILL_ACTIVE;
while (result == STILL_ACTIVE)
{
::MsgWaitForMultipleObjects(0,NULL,FALSE,INFINITE,QS_ALLINPUT);
RunMessagePump();
::GetExitCodeProcess(process,&result);
}
::CloseHandle(process);
}

void InformApp::WriteLog(const char* msg)
Expand Down
5 changes: 4 additions & 1 deletion Inform7/Inform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

// Title
#define INFORM_TITLE "Inform"
#define L_INFORM_TITLE L"Inform"

// Registry locations
#define REGISTRY_PATH_BROWSER "Software\\David Kinder\\Inform\\WebBrowser"
Expand Down Expand Up @@ -104,6 +105,7 @@ class InformApp : public CWinApp
Extensions,
Preferences,
Spelling,
DownloadedExt
};
void SendAllFrames(Changed changed, int value);

Expand All @@ -122,7 +124,8 @@ class InformApp : public CWinApp

void RunMessagePump(void);
int RunCommand(const char* dir, CString& command, OutputSink& output);
void RunCensus(bool wait);
HANDLE RunCensus(bool wait);
void WaitForProcessEnd(HANDLE process);
void WriteLog(const char* msg);
bool IsWaitCursor(void);

Expand Down
Loading

0 comments on commit e16e086

Please sign in to comment.