2008-12-10 05:42:49 +01:00
|
|
|
/*
|
2010-02-28 01:08:10 +01:00
|
|
|
* This file is a part of Winix
|
2008-12-10 05:42:49 +01:00
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-25 00:03:36 +01:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2008-12-10 05:42:49 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
#ifndef headerfile_winix_core_dirs
|
|
|
|
#define headerfile_winix_core_dirs
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2009-04-21 22:50:55 +02:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
#include "item.h"
|
|
|
|
#include "dircontainer.h"
|
2010-09-18 02:51:12 +02:00
|
|
|
#include "db/db.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
#include "request.h"
|
2010-12-02 03:36:49 +01:00
|
|
|
#include "notify/notify.h"
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// we do not support '..' in a path (for simplicity and security reasons)
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
|
|
|
class Dirs
|
2008-12-10 05:42:49 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
void ReadDirs();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
void SetCur(Cur * pcur);
|
2010-08-10 18:12:50 +02:00
|
|
|
void SetDb(Db * pdb);
|
2010-12-02 02:02:02 +01:00
|
|
|
void SetNotify(Notify * pnotify);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// these methods return false if there is no such a dir
|
|
|
|
bool IsDir(long dir_id);
|
2010-10-19 02:31:20 +02:00
|
|
|
bool GetDirChilds(long parent_id, std::vector<Item*> & childs_tab); // !! zamienic na GetChilds()
|
2011-01-05 22:24:11 +01:00
|
|
|
bool MakePath(long dir_id, std::wstring & path, bool clear_path = true);
|
2011-08-02 02:10:45 +02:00
|
|
|
void MakePath(const std::vector<Item*> dir_tab, std::wstring & path, bool clear_path = true);
|
2010-03-15 02:47:26 +01:00
|
|
|
bool ChangeParent(long dir_id, long new_parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2010-03-15 02:47:26 +01:00
|
|
|
bool HasParent(long dir_id, long parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
|
2010-03-15 18:09:45 +01:00
|
|
|
bool DelDir(long dir_id);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2012-01-25 00:03:36 +01:00
|
|
|
// if returns true then out_dir_tab is not empty
|
2011-01-05 22:24:11 +01:00
|
|
|
bool CreateDirTab(long dir_id, std::vector<Item*> & out_dir_tab);
|
|
|
|
|
|
|
|
void LogDir(const std::vector<Item*> & dir_tab);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
int AnalyzePath(const std::wstring & path, long & dir_id, std::wstring & dir, std::wstring & file);
|
2011-01-05 22:24:11 +01:00
|
|
|
int FollowLink(const std::vector<Item*> & current_dir_tab, const std::wstring & link_to,
|
|
|
|
std::vector<Item*> & out_dir_tab, std::wstring & out_item);
|
2010-11-21 01:19:17 +01:00
|
|
|
static void SplitPath(const std::wstring & path, std::wstring & dir, std::wstring & file);
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2011-01-24 00:23:24 +01:00
|
|
|
DirContainer::ParentIterator FindFirstChild(long parent_id);
|
2011-01-05 22:24:11 +01:00
|
|
|
DirContainer::ParentIterator NextChild(DirContainer::ParentIterator i);
|
2011-01-24 00:23:24 +01:00
|
|
|
DirContainer::ParentIterator ParentEnd(); // !! pozostalo do zamiany na child
|
2008-12-30 02:05:03 +01:00
|
|
|
|
2010-03-15 02:47:26 +01:00
|
|
|
|
2009-11-17 02:04:01 +01:00
|
|
|
// these methods return null if there is no such a dir
|
2010-08-10 18:12:50 +02:00
|
|
|
// !! zmienic nazwy wskazujace ze operujemy tylko na lokalnej tablicy
|
2008-12-30 02:05:03 +01:00
|
|
|
Item * GetRootDir();
|
2009-11-16 00:55:11 +01:00
|
|
|
Item * GetEtcDir();
|
2010-11-04 17:46:19 +01:00
|
|
|
Item * GetVarDir();
|
2010-11-21 01:19:17 +01:00
|
|
|
Item * GetDir(const std::wstring & name, long parent);
|
|
|
|
Item * GetDir(const std::wstring & path);
|
2008-12-30 02:05:03 +01:00
|
|
|
Item * GetDir(long id);
|
2009-04-20 00:13:21 +02:00
|
|
|
Item * AddDir(const Item & item);
|
2008-12-31 19:28:12 +01:00
|
|
|
|
2009-02-06 14:12:03 +01:00
|
|
|
void CheckRootDir();
|
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
Item * CreateVarDir();
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-11-04 17:46:19 +01:00
|
|
|
// !! jak juz wczesniejsze nazwy beda zmienione to tutaj damy AddDir() /AddDir() juz istnieje przeciez?/
|
2010-12-02 02:02:02 +01:00
|
|
|
Error AddDirectory(Item & item, bool add_to_dir_tab = false, Item ** pdir = 0, int notify_code = 0);
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2011-06-15 01:45:42 +02:00
|
|
|
// returns how many levels of directories there are
|
|
|
|
// "/" -> 0 (root dir)
|
|
|
|
// "/abc" -> 1
|
|
|
|
// "/abc/def" -> 2
|
|
|
|
size_t DirLevel(long id);
|
|
|
|
|
2011-06-21 23:24:49 +02:00
|
|
|
// checking if child_id is really a child of parent_id
|
|
|
|
bool IsChild(long parent_id, long child_id);
|
|
|
|
|
2009-02-06 14:12:03 +01:00
|
|
|
private:
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
Cur * cur;
|
|
|
|
Db * db;
|
2010-12-02 02:02:02 +01:00
|
|
|
Notify * notify;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
DirContainer dir_tab;
|
2011-01-05 22:24:11 +01:00
|
|
|
std::wstring temp_path;
|
|
|
|
std::wstring temp_link_to;
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
size_t AnalyzeDir(Item * pdir, const std::wstring & path, long & dir_id, std::wstring & dir);
|
2012-01-25 00:03:36 +01:00
|
|
|
bool AnalyzeDir(std::vector<Item*> & dir_tab, const std::wstring & link_to, size_t & i);
|
2010-11-21 01:19:17 +01:00
|
|
|
std::wstring analyze_temp;
|
2011-07-14 01:14:10 +02:00
|
|
|
std::wstring get_dir_temp;
|
2010-03-15 02:47:26 +01:00
|
|
|
|
2011-01-05 22:24:11 +01:00
|
|
|
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);
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool ExtractName(const wchar_t * & s, std::wstring & name);
|
2010-08-10 18:12:50 +02:00
|
|
|
bool HasReadExecAccessForRoot(const Item & item);
|
2009-02-06 14:12:03 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|