Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cached library a warning #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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