Skip to content

Commit

Permalink
Merge commit '98787dac2dff4906f9c1557ca952692468e659bb'
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Jan 19, 2016
2 parents e261569 + 98787da commit 26ec300
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="airdcpp\ViewFile.cpp">
<Filter>Header Files</Filter>
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions airdcpp-core/airdcpp/AdcHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ void AdcHub::handle(AdcCommand::INF, AdcCommand& c) noexcept {

string cid;

OnlineUser* u = 0;
OnlineUser* u = nullptr;
bool newUser = false;
if(c.getParam("ID", 0, cid)) {
u = findUser(CID(cid));
if(u) {
Expand All @@ -208,6 +209,7 @@ void AdcHub::handle(AdcCommand::INF, AdcCommand& c) noexcept {
}
} else {
u = &getUser(c.getFrom(), CID(cid));
newUser = true;
}
} else if(c.getFrom() == AdcCommand::HUB_SID) {
u = &getUser(c.getFrom(), CID());
Expand Down Expand Up @@ -253,8 +255,6 @@ void AdcHub::handle(AdcCommand::INF, AdcCommand& c) noexcept {
u->getUser()->setFlag(User::ASCH);
}

// Cache so that we can fire the correct event for our own identity when the state changes
bool normal = stateNormal();
if(u->getUser() == getMyIdentity().getUser()) {
State oldState = getConnectState();
if (oldState != STATE_NORMAL) {
Expand All @@ -281,14 +281,14 @@ void AdcHub::handle(AdcCommand::INF, AdcCommand& c) noexcept {

fire(ClientListener::UsersUpdated(), this, ouList);
}
} else if (normal) {
} else if (stateNormal()) {
u->getIdentity().updateConnectMode(getMyIdentity(), this);
}

if(u->getIdentity().isHub()) {
setHubIdentity(u->getIdentity());
fire(ClientListener::HubUpdated(), this);
} else if (normal) {
} else if (!newUser) {
fire(ClientListener::UserUpdated(), this, u);
} else {
fire(ClientListener::UserConnected(), this, u);
Expand Down
6 changes: 2 additions & 4 deletions airdcpp-core/airdcpp/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,10 @@ bool ClientManager::getSupportsCCPM(const UserPtr& aUser, string& _error) {
if (!aUser->isOnline()) {
_error = STRING(USER_OFFLINE);
return false;
}
else if (aUser->isNMDC()) {
} else if (aUser->isNMDC()) {
_error = STRING(CCPM_NOT_SUPPORTED_NMDC);
return false;
}
else if (aUser->isSet(User::BOT)) {
} else if (aUser->isSet(User::BOT)) {
_error = STRING(CCPM_NOT_SUPPORTED);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions airdcpp-core/airdcpp/ConnectivityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ void ConnectivityManager::detectConnection() {
}

void ConnectivityManager::setup(bool v4SettingsChanged, bool v6SettingsChanged) {
bool autoDetect4 = SETTING(AUTO_DETECT_CONNECTION) && SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DISABLED;
bool autoDetect6 = SETTING(AUTO_DETECT_CONNECTION6) && SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_DISABLED;
bool autoDetect4 = SETTING(AUTO_DETECT_CONNECTION) && SETTING(INCOMING_CONNECTIONS) != SettingsManager::INCOMING_DISABLED;
bool autoDetect6 = SETTING(AUTO_DETECT_CONNECTION6) && SETTING(INCOMING_CONNECTIONS6) != SettingsManager::INCOMING_DISABLED;

/*{
if((!autoDetect4 && autoDetectedV4) || (!autoDetect6 && autoDetectedV6) || v4SettingsChanged || v6SettingsChanged) {
Expand Down
9 changes: 4 additions & 5 deletions airdcpp-core/airdcpp/DirectoryListing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "AutoSearchManager.h"
#include "Bundle.h"
#include "BZUtils.h"
#include "DirectoryListingManager.h"
#include "Download.h"
#include "DownloadManager.h"
#include "FilteredFile.h"
Expand All @@ -35,7 +34,7 @@
#include "SimpleXMLReader.h"
#include "StringTokenizer.h"
#include "User.h"
#include "ScopedFunctor.h"
#include "ViewFileManager.h"


namespace dcpp {
Expand Down Expand Up @@ -506,8 +505,8 @@ int64_t DirectoryListing::getDirSize(const string& aDir) const noexcept {
return 0;
}

void DirectoryListing::openFile(const File::Ptr& aFile, bool aIsClientView) const throw(QueueException, FileException) {
QueueManager::getInstance()->addOpenedItem(aFile->getName(), aFile->getSize(), aFile->getTTH(), hintedUser, aIsClientView);
bool DirectoryListing::viewAsText(const File::Ptr& aFile) const noexcept {
return ViewFileManager::getInstance()->addFileNotify(aFile->getName(), aFile->getSize(), aFile->getTTH(), hintedUser, true);
}

DirectoryListing::Directory::Ptr DirectoryListing::findDirectory(const string& aName, const Directory::Ptr& current) const noexcept {
Expand Down Expand Up @@ -580,7 +579,7 @@ void DirectoryListing::findNfoImpl(const string& aPath, bool aAllowQueueList, Du

if (!results.empty()) {
try {
openFile(results.front(), !SETTING(NFO_EXTERNAL));
viewAsText(results.front());
} catch (const Exception&) {

}
Expand Down
2 changes: 1 addition & 1 deletion airdcpp-core/airdcpp/DirectoryListing.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class DirectoryListing : public intrusive_ptr_base<DirectoryListing>, public Use
bool downloadDir(const string& aRemoteDir, const string& aTarget, QueueItemBase::Priority prio = QueueItem::DEFAULT, ProfileToken aAutoSearch = 0) noexcept;
bool createBundle(Directory::Ptr& aDir, const string& aTarget, QueueItemBase::Priority prio, ProfileToken aAutoSearch) noexcept;

void openFile(const File::Ptr& aFile, bool isClientView) const throw(QueueException, FileException);
bool viewAsText(const File::Ptr& aFile) const noexcept;

int64_t getTotalListSize(bool adls = false) const noexcept { return root->getTotalSize(adls); }
int64_t getDirSize(const string& aDir) const noexcept;
Expand Down
1 change: 1 addition & 0 deletions airdcpp-core/airdcpp/QueueManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class QueueManager : public Singleton<QueueManager>, public Speaker<QueueManager
QueueItemPtr addList(const HintedUser& HintedUser, Flags::MaskType aFlags, const string& aInitialDir = Util::emptyString, BundlePtr aBundle=nullptr) throw(QueueException, FileException);

/** Add an item that is opened in the client or with an external program */
/** Files that are viewed in the client should be added from ViewFileManager */
QueueItemPtr addOpenedItem(const string& aFileName, int64_t aSize, const TTHValue& aTTH, const HintedUser& aUser, bool aIsClientView, bool aIsText = true) throw(QueueException, FileException);

/** Readd a source that was removed */
Expand Down
1 change: 1 addition & 0 deletions airdcpp-core/airdcpp/StringDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ enum Strings { // @DontAdd
FILE_ALREADY_FINISHED, // "File is already finished"
FILE_ALREADY_QUEUED, // "A file with the same hash exists in a queued directory %1%"
FILE_ALREADY_SHARED, // "Trying to download file already shared! File: "
FILE_ALREADY_VIEWED, // "The file %1% is being viewed already"
FILE_CORRUPTION_FOUND, // "%1% of corrupted segments were found"
FILE_DATE_FORMAT, // "File date format"
FILE_INDEX, // "File index"
Expand Down
23 changes: 23 additions & 0 deletions airdcpp-core/airdcpp/ViewFileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ namespace dcpp {

return p->second;
}

bool ViewFileManager::addFileThrow(const string& aFileName, int64_t aSize, const TTHValue& aTTH, const HintedUser& aUser, bool aIsText) throw(QueueException, FileException) {
if (getFile(aTTH)) {
return false;
}

QueueManager::getInstance()->addOpenedItem(aFileName, aSize, aTTH, aUser, true, aIsText);
return true;
}

bool ViewFileManager::addFileNotify(const string& aFileName, int64_t aSize, const TTHValue& aTTH, const HintedUser& aUser, bool aIsText) noexcept {
try {
if (ViewFileManager::getInstance()->addFileThrow(aFileName, aSize, aTTH, aUser, true)) {
return true;
}

LogManager::getInstance()->message(STRING_F(FILE_ALREADY_VIEWED, aFileName), LogMessage::SEV_NOTIFY);
} catch (const Exception& e) {
LogManager::getInstance()->message(STRING_F(ADD_FILE_ERROR, aFileName % ClientManager::getInstance()->getFormatedNicks(aUser) % e.getError()), LogMessage::SEV_NOTIFY);
}

return false;
}

bool ViewFileManager::removeFile(const TTHValue& aTTH) noexcept {
ViewFilePtr f;
Expand Down
7 changes: 7 additions & 0 deletions airdcpp-core/airdcpp/ViewFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ namespace dcpp {
~ViewFileManager() noexcept;

ViewFileMap getFiles() const noexcept;

// Adds the file and shows a notification in case of errors
bool addFileNotify(const string& aFileName, int64_t aSize, const TTHValue& aTTH, const HintedUser& aUser, bool aIsText) noexcept;

// Adds the file and throws if there are errors
bool addFileThrow(const string& aFileName, int64_t aSize, const TTHValue& aTTH, const HintedUser& aUser, bool aIsText) throw(QueueException, FileException);

bool removeFile(const TTHValue& aTTH) noexcept;

ViewFilePtr getFile(const TTHValue& aTTH) const noexcept;
Expand Down

0 comments on commit 26ec300

Please sign in to comment.