Пример #1
0
Folder* LocalFolder::newChildFolder(string Name) {

	//If the name is invalid return 0
	if (Name.empty())
		return 0;

	//If it already exists bottle out return 0
	if (searchForChild(Name) != 0)
		return 0;

	Folder* returnFolder = 0;

	//Generate the file path
	string fullPath = m_localFolderPath + Name + "/";

	if (mkdir(fullPath.c_str(), 0) == 0) {

		returnFolder = new LocalFolder(Name, fullPath);
		returnFolder->refresh();

		m_entryList.push_back(returnFolder);
	}

	return returnFolder;
}
Пример #2
0
void LocalFolder::refresh() {
#warning May not be compatable with Windows 32
	emptyList();

	DIR* dir = opendir(m_localFolderPath.c_str());
	struct dirent* nextEntry;

	if (dir != 0) {

		while (true) {

			nextEntry = readdir(dir);

			if (nextEntry != 0) {
				//Check it isn't the current or parent indicators
				if (strcmp(nextEntry->d_name, ".") == 0) {
					//Do nothing for this dir
				} else if (strcmp(nextEntry->d_name, "..") == 0) {
					//Do nothing for the dir the level above
				} else {
					//if its not process it

					if (nextEntry->d_type == DT_DIR) {

						//Directory
						string fullPath = m_localFolderPath + nextEntry->d_name
								+ "/";

						Folder* subFolder = new LocalFolder(nextEntry->d_name,
								fullPath);

						subFolder->refresh();

						m_entryList.push_back(subFolder);

					} else {

						//File
						string fullPath = m_localFolderPath + nextEntry->d_name;

						m_entryList.push_back(new LocalFile(fullPath));
					}

				}

			} else {

				break;

			}

		}

		closedir(dir);
		dir = 0;
	}

}