Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/sirjuddington/SLADE
Browse files Browse the repository at this point in the history
  • Loading branch information
IjonTichy committed Jun 2, 2013
2 parents fd57f77 + 5833130 commit 24e0a46
Show file tree
Hide file tree
Showing 384 changed files with 21,056 additions and 11,929 deletions.
28 changes: 18 additions & 10 deletions src/ACSPrefsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ EXTERN_CVAR(String, path_acc_libs)
/* ACSPrefsPanel::ACSPrefsPanel
* ACSPrefsPanel class constructor
*******************************************************************/
ACSPrefsPanel::ACSPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent) {
ACSPrefsPanel::ACSPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent)
{
// Create sizer
wxBoxSizer* psizer = new wxBoxSizer(wxVERTICAL);
SetSizer(psizer);

// Create frame+sizer
wxStaticBox *frame = new wxStaticBox(this, -1, "ACS Preferences");
wxStaticBoxSizer *sizer = new wxStaticBoxSizer(frame, wxVERTICAL);
wxStaticBox* frame = new wxStaticBox(this, -1, "ACS Preferences");
wxStaticBoxSizer* sizer = new wxStaticBoxSizer(frame, wxVERTICAL);
psizer->Add(sizer, 1, wxEXPAND|wxALL, 4);

// ACC.exe path
Expand Down Expand Up @@ -96,20 +97,23 @@ ACSPrefsPanel::ACSPrefsPanel(wxWindow* parent) : PrefsPanelBase(parent) {
/* ACSPrefsPanel::~ACSPrefsPanel
* ACSPrefsPanel class destructor
*******************************************************************/
ACSPrefsPanel::~ACSPrefsPanel() {
ACSPrefsPanel::~ACSPrefsPanel()
{
}

/* ACSPrefsPanel::init
* Initialises panel controls
*******************************************************************/
void ACSPrefsPanel::init() {
void ACSPrefsPanel::init()
{
text_accpath->SetValue(wxString(path_acc));
}

/* ACSPrefsPanel::applyPreferences
* Applies preferences from the panel controls
*******************************************************************/
void ACSPrefsPanel::applyPreferences() {
void ACSPrefsPanel::applyPreferences()
{
path_acc = text_accpath->GetValue();

// Build include paths string
Expand All @@ -131,7 +135,8 @@ void ACSPrefsPanel::applyPreferences() {
/* ACSPrefsPanel::onBtnBrowseACCPath
* Called when the 'Browse' for ACC path button is clicked
*******************************************************************/
void ACSPrefsPanel::onBtnBrowseACCPath(wxCommandEvent& e) {
void ACSPrefsPanel::onBtnBrowseACCPath(wxCommandEvent& e)
{
// Setup acc executable file string
string acc_exe = "acc";
#ifdef WIN32
Expand All @@ -145,14 +150,17 @@ void ACSPrefsPanel::onBtnBrowseACCPath(wxCommandEvent& e) {
}


void ACSPrefsPanel::onBtnAddIncPath(wxCommandEvent& e) {
void ACSPrefsPanel::onBtnAddIncPath(wxCommandEvent& e)
{
wxDirDialog dlg(this, "Browse for ACC Include Path");
if (dlg.ShowModal() == wxID_OK) {
if (dlg.ShowModal() == wxID_OK)
{
list_inc_paths->Append(dlg.GetPath());
}
}

void ACSPrefsPanel::onBtnRemoveIncPath(wxCommandEvent& e) {
void ACSPrefsPanel::onBtnRemoveIncPath(wxCommandEvent& e)
{
if (list_inc_paths->GetSelection() >= 0)
list_inc_paths->Delete(list_inc_paths->GetSelection());
}
3 changes: 2 additions & 1 deletion src/ACSPrefsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "PrefsPanelBase.h"

class ACSPrefsPanel : public PrefsPanelBase {
class ACSPrefsPanel : public PrefsPanelBase
{
private:
wxTextCtrl* text_accpath;
wxButton* btn_browse_accpath;
Expand Down
79 changes: 52 additions & 27 deletions src/ADatArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,39 @@ EXTERN_CVAR(Bool, archive_load_data)
/* ADatArchive::ADatArchive
* ADatArchive class constructor
*******************************************************************/
ADatArchive::ADatArchive() : Archive(ARCHIVE_ADAT) {
ADatArchive::ADatArchive() : Archive(ARCHIVE_ADAT)
{
}

/* ADatArchive::~ADatArchive
* ADatArchive class destructor
*******************************************************************/
ADatArchive::~ADatArchive() {
ADatArchive::~ADatArchive()
{
}

/* ADatArchive::getFileExtensionString
* Returns the file extension string to use in the file open dialog
*******************************************************************/
string ADatArchive::getFileExtensionString() {
string ADatArchive::getFileExtensionString()
{
return "Dat Files (*.dat)|*.dat";
}

/* ADatArchive::getFormat
* Returns the string id for the dat EntryDataFormat
*******************************************************************/
string ADatArchive::getFormat() {
string ADatArchive::getFormat()
{
return "archive_adat";
}

/* ADatArchive::open
* Reads dat format data from a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool ADatArchive::open(MemChunk& mc) {
bool ADatArchive::open(MemChunk& mc)
{
// Check given data is valid
if (mc.getSize() < 16)
return false;
Expand All @@ -95,7 +100,8 @@ bool ADatArchive::open(MemChunk& mc) {
mc.read(&dir_size, 4);

// Check it
if (magic[0] != 'A' || magic[1] != 'D' || magic[2] != 'A' || magic[3] != 'T') {
if (magic[0] != 'A' || magic[1] != 'D' || magic[2] != 'A' || magic[3] != 'T')
{
wxLogMessage("ADatArchive::open: Opening failed, invalid header");
Global::error = "Invalid dat header";
return false;
Expand All @@ -108,7 +114,8 @@ bool ADatArchive::open(MemChunk& mc) {
size_t num_entries = dir_size / DIRENTRY;
mc.seek(dir_offset, SEEK_SET);
theSplashWindow->setProgressMessage("Reading dat archive data");
for (uint32_t d = 0; d < num_entries; d++) {
for (uint32_t d = 0; d < num_entries; d++)
{
// Update splash window progress
theSplashWindow->setProgress(((float)d / (float)num_entries));

Expand All @@ -130,7 +137,8 @@ bool ADatArchive::open(MemChunk& mc) {
compsize = wxINT32_SWAP_ON_BE(compsize);

// Check offset+size
if ((unsigned)(offset + compsize) > mc.getSize()) {
if ((unsigned)(offset + compsize) > mc.getSize())
{
wxLogMessage("ADatArchive::open: dat archive is invalid or corrupt (entry goes past end of file)");
Global::error = "Archive is invalid and/or corrupt";
setMuted(false);
Expand Down Expand Up @@ -159,21 +167,24 @@ bool ADatArchive::open(MemChunk& mc) {
vector<ArchiveEntry*> all_entries;
getEntryTreeAsList(all_entries);
theSplashWindow->setProgressMessage("Detecting entry types");
for (size_t a = 0; a < all_entries.size(); a++) {
for (size_t a = 0; a < all_entries.size(); a++)
{
// Update splash window progress
theSplashWindow->setProgress((((float)a / (float)num_entries)));

// Get entry
ArchiveEntry* entry = all_entries[a];

// Read entry data if it isn't zero-sized
if (entry->getSize() > 0) {
if (entry->getSize() > 0)
{
// Read the entry data
mc.exportMemChunk(edata, (int)entry->exProp("Offset"), entry->getSize());
MemChunk xdata;
if (Compression::ZlibInflate(edata, xdata, (int)entry->exProp("FullSize")))
entry->importMemChunk(xdata);
else {
else
{
wxLogMessage("Entry %s couldn't be inflated", CHR(entry->getName()));
entry->importMemChunk(edata);
}
Expand Down Expand Up @@ -204,7 +215,8 @@ bool ADatArchive::open(MemChunk& mc) {
* Writes the dat archive to a MemChunk
* Returns true if successful, false otherwise
*******************************************************************/
bool ADatArchive::write(MemChunk& mc, bool update) {
bool ADatArchive::write(MemChunk& mc, bool update)
{
// Clear current data
mc.clear();
MemChunk directory;
Expand All @@ -226,23 +238,28 @@ bool ADatArchive::write(MemChunk& mc, bool update) {
mc.write(&version, 4);

// Write entry data
for (unsigned a = 0; a < entries.size(); a++) {
for (unsigned a = 0; a < entries.size(); a++)
{
// Skip folders
if (entries[a]->getType() == EntryType::folderType())
continue;

// Create compressed version of the lump
MemChunk * entry = NULL;
if (Compression::ZlibDeflate(entries[a]->getMCData(), compressed, 9)) {
MemChunk* entry = NULL;
if (Compression::ZlibDeflate(entries[a]->getMCData(), compressed, 9))
{
entry = &compressed;
} else {
}
else
{
entry = &(entries[a]->getMCData());
wxLogMessage("Entry %s couldn't be deflated", CHR(entries[a]->getName()));
}

// Update entry
int offset = mc.currentPos();
if (update) {
if (update)
{
entries[a]->setState(0);
entries[a]->exProp("Offset") = (int)offset;
}
Expand All @@ -254,7 +271,8 @@ bool ADatArchive::write(MemChunk& mc, bool update) {
// Check entry name
string name = entries[a]->getPath(true);
name.Remove(0, 1); // Remove leading /
if (name.Len() > 128) {
if (name.Len() > 128)
{
wxLogMessage("Warning: Entry %s path is too long (> 128 characters), putting it in the root directory", CHR(name));
wxFileName fn(name);
name = fn.GetFullName();
Expand Down Expand Up @@ -290,7 +308,7 @@ bool ADatArchive::write(MemChunk& mc, bool update) {
// Step 2: Write entry data //
//////////////////////////////

mc.write(entry->getData(), entry->getSize());
mc.write(entry->getData(), entry->getSize());
}

// Write directory
Expand All @@ -311,7 +329,8 @@ bool ADatArchive::write(MemChunk& mc, bool update) {
* Writes the dat archive to a file
* Returns true if successful, false otherwise
*******************************************************************/
bool ADatArchive::write(string filename, bool update) {
bool ADatArchive::write(string filename, bool update)
{
// Write to a MemChunk, then export it to a file
MemChunk mc;
if (write(mc, true))
Expand All @@ -324,23 +343,26 @@ bool ADatArchive::write(string filename, bool update) {
* Loads an entry's data from the dat file
* Returns true if successful, false otherwise
*******************************************************************/
bool ADatArchive::loadEntryData(ArchiveEntry* entry) {
bool ADatArchive::loadEntryData(ArchiveEntry* entry)
{
// Check entry is ok
if (!checkEntry(entry))
return false;

// Do nothing if the entry's size is zero,
// or if it has already been loaded
if (entry->getSize() == 0 || entry->isLoaded()) {
if (entry->getSize() == 0 || entry->isLoaded())
{
entry->setLoaded();
return true;
}

// Open archive file
wxFile file(filename);

// Check it opened
if (!file.IsOpened()) {
if (!file.IsOpened())
{
wxLogMessage("ADatArchive::loadEntryData: Unable to open archive file %s", CHR(filename));
return false;
}
Expand All @@ -358,7 +380,8 @@ bool ADatArchive::loadEntryData(ArchiveEntry* entry) {
/* ADatArchive::detectNamespace
* Returns the namespace that [entry] is within
*******************************************************************/
string ADatArchive::detectNamespace(ArchiveEntry* entry) {
string ADatArchive::detectNamespace(ArchiveEntry* entry)
{
// Check entry
if (!checkEntry(entry))
return "global";
Expand Down Expand Up @@ -386,7 +409,8 @@ string ADatArchive::detectNamespace(ArchiveEntry* entry) {
/* ADatArchive::isADatArchive
* Checks if the given data is a valid Anachronox dat archive
*******************************************************************/
bool ADatArchive::isADatArchive(MemChunk& mc) {
bool ADatArchive::isADatArchive(MemChunk& mc)
{
// Check it opened ok
if (mc.getSize() < 16)
return false;
Expand Down Expand Up @@ -425,7 +449,8 @@ bool ADatArchive::isADatArchive(MemChunk& mc) {
/* ADatArchive::isADatArchive
* Checks if the file at [filename] is a valid Anachronox dat archive
*******************************************************************/
bool ADatArchive::isADatArchive(string filename) {
bool ADatArchive::isADatArchive(string filename)
{
// Open file for reading
wxFile file(filename);

Expand Down
3 changes: 2 additions & 1 deletion src/ADatArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

#include "Archive.h"

class ADatArchive : public Archive {
class ADatArchive : public Archive
{
private:

public:
Expand Down
Loading

0 comments on commit 24e0a46

Please sign in to comment.