115 lines
3.2 KiB
C++
Executable File
115 lines
3.2 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2011, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfile_winix_core_dirs
|
|
#define headerfile_winix_core_dirs
|
|
|
|
|
|
#include <vector>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include "item.h"
|
|
#include "dircontainer.h"
|
|
#include "db/db.h"
|
|
#include "request.h"
|
|
#include "notify/notify.h"
|
|
|
|
|
|
// we do not support '..' in a path (for simplicity and security reasons)
|
|
|
|
|
|
class Dirs
|
|
{
|
|
public:
|
|
|
|
void Clear();
|
|
void ReadDirs();
|
|
|
|
void SetCur(Cur * pcur);
|
|
void SetDb(Db * pdb);
|
|
void SetNotify(Notify * pnotify);
|
|
|
|
// these methods return false if there is no such a dir
|
|
bool IsDir(long dir_id);
|
|
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
|
|
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
|
|
void MakePath(const std::vector<Item*> dir_tab, std::wstring & path, bool clear_path = true);
|
|
bool ChangeParent(long dir_id, long new_parent_id);
|
|
|
|
bool HasParent(long dir_id, long parent_id);
|
|
|
|
bool DelDir(long dir_id);
|
|
|
|
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
|
|
|
|
void LogDir(const std::vector<Item*> & dir_tab);
|
|
|
|
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
|
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
|
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
|
|
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
|
|
|
|
DirContainer::ParentIterator FindFirstChild(long parent_id);
|
|
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
|
|
DirContainer::ParentIterator ParentEnd(); // !! pozostalo do zamiany na child
|
|
|
|
|
|
// these methods return null if there is no such a dir
|
|
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
|
|
Item * GetRootDir();
|
|
Item * GetEtcDir();
|
|
Item * GetVarDir();
|
|
Item * GetDir(const std::wstring & name, long parent);
|
|
Item * GetDir(const std::wstring & path);
|
|
Item * GetDir(long id);
|
|
Item * AddDir(const Item & item);
|
|
|
|
void CheckRootDir();
|
|
|
|
Item * CreateVarDir();
|
|
|
|
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
|
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
|
|
|
// returns how many levels of directories there are
|
|
// "/" -> 0 (root dir)
|
|
// "/abc" -> 1
|
|
// "/abc/def" -> 2
|
|
size_t DirLevel(long id);
|
|
|
|
// checking if child_id is really a child of parent_id
|
|
bool IsChild(long parent_id, long child_id);
|
|
|
|
private:
|
|
|
|
Cur * cur;
|
|
Db * db;
|
|
Notify * notify;
|
|
|
|
DirContainer dir_tab;
|
|
std::wstring temp_path;
|
|
std::wstring temp_link_to;
|
|
|
|
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
|
|
size_t AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to);
|
|
std::wstring analyze_temp;
|
|
std::wstring get_dir_temp;
|
|
|
|
void CopyDirTab(const std::vector<Item*> & in, std::vector<Item*> & out);
|
|
int FollowLink(std::vector<Item*> & dir_tab, const std::wstring & link_to, std::wstring & out_item);
|
|
|
|
bool ExtractName(const wchar_t * & s, std::wstring & name);
|
|
bool HasReadExecAccessForRoot(const Item & item);
|
|
|
|
};
|
|
|
|
|
|
#endif
|