Skip to content

Commit 254255a

Browse files
committed
Plugins can now save state, even if save_state not enabled
1 parent 0929663 commit 254255a

File tree

5 files changed

+61
-68
lines changed

5 files changed

+61
-68
lines changed

OtherTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ class CPlugin :public CObject
10061006

10071007
CPlugin (CMUSHclientDoc * pDoc); // constructor
10081008
~CPlugin (); // destructor
1009-
bool SaveState (void);
1009+
bool SaveState (const bool bScripted = false);
10101010
DISPID GetPluginDispid (const char * sName);
10111011
void ExecutePluginScript (const char * sName,
10121012
DISPID & iRoutine); // no arguments

dialogs/plugins/PluginsDlg.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,6 @@ void CPluginsDlg::OnRdblclkPluginsList(NMHDR* pNMHDR, LRESULT* pResult)
689689
if (!pos)
690690
continue;
691691

692-
// no state file, don't bother
693-
if (!(p->m_bSaveState))
694-
continue;
695-
696692
// need a directory
697693
CString strName = CString (Make_Absolute_Path (App.m_strDefaultStateFilesDirectory));
698694

plugins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ void CPlugin::ExecutePluginScript (const char * sName,
601601

602602
} // end of CPlugin::ExecutePluginScript
603603

604-
bool CPlugin::SaveState (void)
604+
bool CPlugin::SaveState (const bool bScripted)
605605
{
606606

607-
if (!m_bSaveState)
607+
if (!m_bSaveState && !bScripted)
608608
return true; // not needed
609609

610610
// need a directory

scripting/methods.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5748,10 +5748,7 @@ long CMUSHclientDoc::SaveState()
57485748
if (!m_CurrentPlugin)
57495749
return eNotAPlugin;
57505750

5751-
if (!m_CurrentPlugin->m_bSaveState)
5752-
return ePluginDoesNotSaveState;
5753-
5754-
if (m_CurrentPlugin->SaveState ())
5751+
if (m_CurrentPlugin->SaveState (true))
57555752
return ePluginCouldNotSaveState;
57565753

57575754
return eOK;

xml/xml_load_world.cpp

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,87 +2328,87 @@ void CMUSHclientDoc::Load_Plugin_XML (CXMLelement & parent)
23282328
// find <description> text
23292329
FindNodeContents (*node, "description", m_CurrentPlugin->m_strDescription, false);
23302330

2331-
// load the state
2332-
if (m_CurrentPlugin->m_bSaveState)
2333-
{
2334-
CString strSavedFileName = strFileName;
2335-
int iSavedLineLastItemFound = iLineLastItemFound;
2336-
int iSavedErrorCount = iErrorCount;
2331+
CString strSavedFileName = strFileName;
2332+
int iSavedLineLastItemFound = iLineLastItemFound;
2333+
int iSavedErrorCount = iErrorCount;
23372334

2338-
CFile * f = NULL;
2339-
CArchive * ar = NULL;
2340-
CXMLparser parser;
2335+
CFile * f = NULL;
2336+
CArchive * ar = NULL;
2337+
CXMLparser parser;
23412338

2342-
strFileName = CString (Make_Absolute_Path (App.m_strDefaultStateFilesDirectory));
2343-
// need a directory
2344-
2345-
if (App.m_strPluginsDirectory.IsEmpty ())
2346-
ThrowErrorException ("No plugins directory specified");
2339+
strFileName = CString (Make_Absolute_Path (App.m_strDefaultStateFilesDirectory));
2340+
// need a directory
2341+
2342+
if (App.m_strPluginsDirectory.IsEmpty ())
2343+
ThrowErrorException ("No plugins directory specified");
23472344

2348-
// need a world id
2345+
// need a world id
23492346

2350-
if (m_strWorldID.IsEmpty ())
2351-
ThrowErrorException ("No world ID specified");
2347+
if (m_strWorldID.IsEmpty ())
2348+
ThrowErrorException ("No world ID specified");
23522349

2353-
strFileName += m_strWorldID; // world ID
2354-
strFileName += "-";
2355-
strFileName += m_CurrentPlugin->m_strID; // plugin ID
2356-
strFileName += "-state.xml"; // suffix
2350+
strFileName += m_strWorldID; // world ID
2351+
strFileName += "-";
2352+
strFileName += m_CurrentPlugin->m_strID; // plugin ID
2353+
strFileName += "-state.xml"; // suffix
23572354

23582355
// ::TMessageBox ("Plugin Load State");
23592356

2360-
try
2357+
try
2358+
{
2359+
f = new CFile (strFileName, CFile::modeRead | CFile::shareDenyWrite);
2360+
2361+
ar = new CArchive(f, CArchive::load);
2362+
2363+
if (IsArchiveXML (*ar))
23612364
{
2362-
f = new CFile (strFileName, CFile::modeRead | CFile::shareDenyWrite);
23632365

2364-
ar = new CArchive(f, CArchive::load);
2365-
2366-
if (IsArchiveXML (*ar))
2366+
try
23672367
{
2368+
Load_World_XML (*ar,
2369+
XML_VARIABLES | XML_NO_PLUGINS | XML_OVERWRITE,
2370+
0);
2371+
}
2372+
catch (CArchiveException* e)
2373+
{
2374+
e->Delete ();
2375+
ThrowErrorException ("Error processing plugin state file \"%s\"",
2376+
(LPCTSTR) strFileName);
2377+
} // end of catch
23682378

2369-
try
2370-
{
2371-
Load_World_XML (*ar,
2372-
XML_VARIABLES | XML_NO_PLUGINS | XML_OVERWRITE,
2373-
0);
2374-
}
2375-
catch (CArchiveException* e)
2376-
{
2377-
e->Delete ();
2378-
ThrowErrorException ("Error processing plugin state file \"%s\"",
2379-
(LPCTSTR) strFileName);
2380-
} // end of catch
2381-
2382-
}
2383-
else
2379+
}
2380+
else
2381+
{
2382+
// ignore empty state files
2383+
if (ar->GetFile ()->GetLength () > 0)
23842384
ThrowErrorException ("Plugin state \"%s\" is not an XML file",
23852385
(LPCTSTR) strFileName);
23862386

2387-
} // end of try
2387+
} // end of not archive
2388+
} // end of try
23882389

2389-
catch(CFileException*)
2390-
{
2391-
// silently ignore no state file :)
2390+
catch(CFileException*)
2391+
{
2392+
// silently ignore no state file :)
23922393
// HandleLoadException ("plugin state file not found, assuming empty", e);
2393-
}
2394-
2395-
catch(CException*)
2396-
{
2397-
strFileName = strSavedFileName;
2398-
iLineLastItemFound = iSavedLineLastItemFound;
2399-
iErrorCount = iSavedErrorCount;
2400-
delete ar;
2401-
delete f;
2402-
throw;
2403-
}
2394+
}
24042395

2396+
catch(CException*)
2397+
{
24052398
strFileName = strSavedFileName;
24062399
iLineLastItemFound = iSavedLineLastItemFound;
24072400
iErrorCount = iSavedErrorCount;
24082401
delete ar;
24092402
delete f;
2403+
throw;
2404+
}
2405+
2406+
strFileName = strSavedFileName;
2407+
iLineLastItemFound = iSavedLineLastItemFound;
2408+
iErrorCount = iSavedErrorCount;
2409+
delete ar;
2410+
delete f;
24102411

2411-
} // end of getting the state
24122412

24132413
}
24142414
catch (CException*)

0 commit comments

Comments
 (0)