repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / diskusage / Snapshot.cpp
blobbef48b9b7923159b266e7e61f6637839d01662de
1 /*
2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT/X11 license.
5 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software
6 * as long as it is accompanied by it's documentation and this copyright notice.
7 * The software comes with no warranty, etc.
8 */
11 #include "Snapshot.h"
13 #include <stdio.h>
14 #include <string.h>
16 #include <Directory.h>
17 #include <Mime.h>
18 #include <NodeInfo.h>
19 #include <Path.h>
20 #include <Volume.h>
23 static const char* kFileType = B_FILE_MIME_TYPE;
24 static const char* kDirType = "application/x-vnd.Be-directory";
25 static const char* kVolumeType = "application/x-vnd.Be-volume";
28 FileInfo::FileInfo()
30 pseudo(false),
31 size(0),
32 count(0),
33 parent(NULL),
34 children()
39 FileInfo::~FileInfo()
41 while (children.size() != 0) {
42 FileInfo* child = *children.begin();
43 delete child;
44 children.erase(children.begin());
49 void
50 FileInfo::GetPath(string& path) const
52 if (pseudo) {
53 path.assign(ref.name);
54 } else {
55 BEntry entry(&ref, true);
56 BPath pathObj(&entry);
57 path.assign(pathObj.Path());
62 FileInfo*
63 FileInfo::FindChild(const char* name) const
65 vector<FileInfo*>::const_iterator i = children.begin();
66 while (i != children.end()) {
67 if (strcmp((*i)->ref.name, name) == 0)
68 return *i;
69 i++;
72 return NULL;
76 BMimeType*
77 FileInfo::Type() const
79 char mimeStr[B_MIME_TYPE_LENGTH] = { '\0' };
80 if (parent == NULL) {
81 // This is the volume's root directory; treat it as a volume type.
82 strlcpy(mimeStr, kVolumeType, sizeof(mimeStr));
83 } else {
84 // Get the MIME type from the registrar.
85 BNode node(&ref);
86 if (node.InitCheck() == B_OK) {
87 BNodeInfo nodeInfo(&node);
88 if (nodeInfo.InitCheck() == B_OK) {
89 status_t s = nodeInfo.GetType(mimeStr);
90 if (s != B_OK && children.size() > 0) {
91 if (s == B_ENTRY_NOT_FOUND) {
92 // This status appears to be returned only for files on
93 // BFS volumes (e.g., CDFS volumes return B_BAD_VALUE).
94 //nodeInfo.SetType(kDirType);
96 strlcpy(mimeStr, kDirType, sizeof(mimeStr));
102 if (strlen(mimeStr) == 0)
103 strlcpy(mimeStr, kFileType, sizeof(mimeStr));
105 return new BMimeType(mimeStr);
109 // #pragma mark -
112 VolumeSnapshot::VolumeSnapshot(const BVolume* volume)
114 char nameBuffer[B_FILE_NAME_LENGTH];
115 volume->GetName(nameBuffer);
116 name = nameBuffer;
118 capacity = volume->Capacity();
119 freeBytes = volume->FreeBytes();
120 rootDir = NULL;
121 freeSpace = NULL;
125 VolumeSnapshot::~VolumeSnapshot()
127 delete rootDir;
128 delete freeSpace;