Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ xcuserdata/
# End of https://www.toptal.com/developers/gitignore/api/xcode

build/
build.xcresult/
build.xcresult/
/archive.xcarchive
2 changes: 1 addition & 1 deletion MacDependency/ArchitectureModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Cocoa/Cocoa.h>
#import "MachOModel.h"
#include "macho/machoarchitecture.h"
#include "MachO/machoarchitecture.h"
#include "MachO/machoheader.h"

@class MyDocument;
Expand Down
9 changes: 4 additions & 5 deletions MacDependency/MachOModel.mm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these changes, but prefer the systemPurpleColor colour as used by the original suggester for the warning colour.

Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ - (id) initWithFilename:(std::string&)filename command:(DylibCommand*)aCommand d
NSString* log = [NSString stringWithFormat:NSLocalizedString(@"ERR_ARCHITECTURE_MISMATCH", nil), filename.c_str(), [parent name]];
[aDocument appendLogLine:log withModel:self state:state];
}

} catch (MachOException& exc) {
[self setStateWithWarning:isWeakReference];
} catch (MachOException& exc) {
[self setStateWithWarning:isWeakReference || exc.isWarning()];
NSString* log = [NSString stringWithStdString:exc.getCause()];
[aDocument appendLogLine:log withModel:self state:state];
// distinguish between weak and strong. In both cases append to tree with a status color
Expand Down Expand Up @@ -176,10 +175,10 @@ - (NSColor*) textColor {
NSColor* color;
switch(state) {
case StateWarning:
color = [NSColor systemOrangeColor];
color = [NSColor systemYellowColor];
break;
case StateError:
color = [NSColor systemOrangeColor];
color = [NSColor systemRedColor];
break;
default:
color = [NSColor labelColor];
Expand Down
12 changes: 9 additions & 3 deletions MachO/internalfile.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "internalfile.h"
#include "machoexception.h"

#include <dlfcn.h>

// use reference counting to reuse files for all used architectures
InternalFile* InternalFile::create(InternalFile* file) {
file->counter++;
Expand All @@ -24,9 +26,13 @@ filename(filename), counter(1)
// open file handle
file.open(this->filename, std::ios_base::in | std::ios_base::binary);
if (file.fail()) {
std::ostringstream error;
error << "Couldn't open file '" << filename << "'.";
throw MachOException(error.str());
void* dylib = dlopen(this->filename.c_str(), RTLD_LAZY);
if (dylib) {
dlclose(dylib);
throw MachOException("System cached library '" + filename + "'.", true);
} else {
throw MachOException("Couldn't open file '" + filename + "'.");
}
}

struct stat buffer;
Expand Down
5 changes: 4 additions & 1 deletion MachO/machoexception.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "machoexception.h"

MachOException::MachOException(const std::string& cause) : cause(cause)
MachOException::MachOException(const std::string& cause) : cause(cause), warning(false)
{
}

MachOException::MachOException(const std::string& cause, bool warning) : cause(cause), warning(warning)
{
}
3 changes: 3 additions & 0 deletions MachO/machoexception.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ class EXPORT MachOException
{
public:
MachOException(const std::string&);
MachOException(const std::string&, bool warning);
const std::string& getCause() { return cause; }
const bool isWarning() { return warning; }
private:
const std::string cause;
bool warning;
};

#endif // MACHOEXCEPTION_H