⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sharing.h

📁 Last change: 2008-02-03 This is the source code of KCeasy。
💻 H
字号:
/*
This file is part of KCeasy (http://www.kceasy.com)
Copyright (C) 2002-2004 Markus Kern <mkern@kceasy.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
*/
//---------------------------------------------------------------------------
#ifndef SharingH
#define SharingH

#include <list.h>
#include <map.h>

#include "Engine.h"
#include "MetaData.h"
#include "Magnet.h"
//---------------------------------------------------------------------------

namespace KCeasyEngine {

using std::list;
using std::map;

class TSharedFile
{
friend class TShares;
friend class TEngine;
friend class TDownload;
public:

    void* GetUData() const { return UData; }
    void SetUData(void* NUData) { UData = NUData; }

    const THashSet* GetHashes() const { return Hashes; }
    string GetMagnetStr() const;

    string FileName;
    string FileDir;
    unsigned int FileSize;
    string MimeType;
    TFileType FileType;

    TMetaData MetaData;

    bool AddedManually; // true if file was added instead of retrieved from giFT

private:
    TSharedFile();
    TSharedFile(const TSharedFile* File);
    ~TSharedFile();

    void* UData;
    THashSet* Hashes;
};


class TShares
{
friend class TEngine;
public:
    typedef list<TSharedFile*>::iterator TFilesIterator;
    typedef list<string>::iterator TDirsIterator;

    bool Hide(bool Hide = true);
    bool UpdateHide();
    bool Sync();
    bool IsHidden() { return Hidden; }
    bool IsSyncing() { return Syncing; }

    // dirs, currently only works if ConnectedLocally is true
    bool UpdateDirs(); // upates shared dirs and completed / incoming

    bool SetCompletedDir(const string& NCompletedDir);
    bool SetIncomingDir(const string& NIncomingDir);
    const string& GetCompletedDir() { return CompletedDir; }
    const string& GetIncomingDir() { return IncomingDir; }

    bool AddDir(const string& SharedDir);
    bool RemoveDir(const string& SharedDir);
    bool SetDirs(const list<string>& NewDirs);
    const list<string>& GetDirs() { return Dirs; }

    void LockDirs() { DirsCritSec.Enter(); }
    void ReleaseDirs() { DirsCritSec.Leave(); }
    TDirsIterator GetDirsBegin() { return Dirs.begin(); }
    TDirsIterator GetDirsEnd() { return Dirs.end(); }
    bool UpdatingDirs() { return DirsGiftId; }
    int NoOfDirs() { return Dirs.size(); }

    // files
    bool UpdateFiles(); // triggers async update of files
    bool RemoveFile(TSharedFile* SharedFile); // after the call SharedFile is invalid
    bool RenameFile(TSharedFile* SharedFile, const string& NewFileName); // rename share
    bool AddFile(const TSharedFile* SharedFile); // adds a copy of SharedFile
    TSharedFile* GetFileByHashes(const THashSet* Hashes);
    TSharedFile* GetFileByPath(const string& Path);

    void LockFiles() { FilesCritSec.Enter(); }
    void ReleaseFiles() { FilesCritSec.Leave(); }
    TFilesIterator GetFilesBegin() { return Files.begin(); }
    TFilesIterator GetFilesEnd() { return Files.end(); }
    bool UpdatingFiles() { return FilesGiftId != 0; }
    int NoOfFiles() { return Files.size(); }

    // bandwidth settings and other stuff. not sure why this is here
    bool GetSharingEnabled();
    bool SetSharingEnabled(bool Enabled);
    bool GetKeepCorruptedDownloads();
    bool SetKeepCorruptedDownloads(bool Keep);
    int GetMaxUploads();
    bool SetMaxUploads(int No); // 0 == no limit
    int GetMaxPerUserUploads();
    bool SetMaxPerUserUploads(int No);
    unsigned int GetUploadBandwidth(); // 0 == no limit
    bool SetUploadBandwidth(unsigned int Bps);
    unsigned int GetDownloadBandwidth(); // 0 == no limit
    bool SetDownloadBandwidth(unsigned int Bps);

    void* GetUData() { return UData; }
    void SetUData(void* NUData) { UData = NUData; }

private:
    TShares(TEngine* ParentEngine);
    ~TShares();

    bool ProcessItem(TGiftCommand* Cmd);
    bool ProcessShare(TGiftCommand* Cmd);

    TEngine* Engine;
    void* UData;
    unsigned int FilesGiftId;
    unsigned int DirsGiftId;

    bool Hidden;
    bool Syncing;

    // dirs
    string CompletedDir;
    string IncomingDir;
    list<string> Dirs;
    TCriticalSection DirsCritSec;

    // files
    list<TSharedFile*> Files;
    TCriticalSection FilesCritSec;
};

} // namespace KCeasyEngine

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -