-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDirectoryItem.cpp
113 lines (92 loc) · 2.32 KB
/
DirectoryItem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* HLLib
* Copyright (C) 2006-2010 Ryan Gregg
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later
* version.
*/
#include "DirectoryItem.h"
#include "DirectoryFile.h"
#include "DirectoryFolder.h"
using namespace HLLib;
CDirectoryItem::CDirectoryItem(const hlChar *lpName, hlUInt uiID, hlVoid *pData, CPackage *pPackage, CDirectoryFolder *pParent) : uiID(uiID), pData(pData), pPackage(pPackage), pParent(pParent)
{
this->lpName = new hlChar[strlen(lpName) + 1];
strcpy(this->lpName, lpName);
}
CDirectoryItem::~CDirectoryItem()
{
delete []this->lpName;
}
//
// GetName()
// Returns this directory item's name.
//
const hlChar *CDirectoryItem::GetName() const
{
return this->lpName;
}
//
// GetID()
// Returns this directory item's ID.
//
hlUInt CDirectoryItem::GetID() const
{
return this->uiID;
}
//
// GetData()
// Returns this directory item's data.
//
hlVoid *CDirectoryItem::GetData()
{
return this->pData;
}
const hlVoid *CDirectoryItem::GetData() const
{
return this->pData;
}
//
// GetPackage()
// Returns this directory item's package.
//
CPackage *CDirectoryItem::GetPackage()
{
return this->pPackage;
}
const CPackage *CDirectoryItem::GetPackage() const
{
return this->pPackage;
}
//
// GetParent()
// Returns this directory item's parent item. If this
// directory item does not have a parent null is returned.
//
CDirectoryFolder *CDirectoryItem::GetParent()
{
return this->pParent;
}
const CDirectoryFolder *CDirectoryItem::GetParent() const
{
return this->pParent;
}
hlVoid CDirectoryItem::GetPath(hlChar *lpPath, hlUInt uiPathSize) const
{
hlChar *lpTemp = new hlChar[uiPathSize];
strncpy(lpPath, this->lpName, uiPathSize);
lpPath[uiPathSize - 1] = '\0';
const CDirectoryItem *pItem = this->pParent;
while(pItem)
{
strcpy(lpTemp, lpPath);
strncpy(lpPath, pItem->lpName, uiPathSize);
lpPath[uiPathSize - 1] = '\0';
strncat(lpPath, PATH_SEPARATOR_STRING, uiPathSize - strlen(lpPath) - 1);
strncat(lpPath, lpTemp, uiPathSize - strlen(lpPath) - 1);
pItem = pItem->pParent;
}
delete []lpTemp;
}