forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileSpec.h
More file actions
78 lines (63 loc) · 2.28 KB
/
fileSpec.h
File metadata and controls
78 lines (63 loc) · 2.28 KB
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
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file fileSpec.h
* @author drose
* @date 2009-06-29
*/
#ifndef FILESPEC_H
#define FILESPEC_H
#include "get_tinyxml.h"
#include <string>
/**
* This simple class is used both within the core API in this module, as well
* as within the plugin_npapi plugin implementation, to represent a file on
* disk that may need to be verified or (re)downloaded.
*/
class FileSpec {
public:
FileSpec();
FileSpec(const FileSpec ©);
void operator = (const FileSpec ©);
~FileSpec();
void load_xml(TiXmlElement *xelement);
void store_xml(TiXmlElement *xelement);
inline const std::string &get_filename() const;
inline void set_filename(const std::string &filename);
inline std::string get_pathname(const std::string &package_dir) const;
inline size_t get_size() const;
inline time_t get_timestamp() const;
inline bool has_hash() const;
bool quick_verify(const std::string &package_dir);
bool quick_verify_pathname(const std::string &pathname);
bool full_verify(const std::string &package_dir);
inline const FileSpec *get_actual_file() const;
const FileSpec *force_get_actual_file(const std::string &pathname);
bool check_hash(const std::string &pathname) const;
bool read_hash(const std::string &pathname);
bool read_hash_stream(std::istream &in);
int compare_hash(const FileSpec &other) const;
void write(std::ostream &out) const;
void output_hash(std::ostream &out) const;
private:
bool priv_check_hash(const std::string &pathname, void *stp);
static inline int decode_hexdigit(char c);
static inline char encode_hexdigit(int c);
static bool decode_hex(unsigned char *dest, const char *source, size_t size);
static void encode_hex(char *dest, const unsigned char *source, size_t size);
static void stream_hex(std::ostream &out, const unsigned char *source, size_t size);
enum { hash_size = 16 };
std::string _filename;
size_t _size;
time_t _timestamp;
unsigned char _hash[hash_size];
bool _got_hash;
FileSpec *_actual_file;
};
#include "fileSpec.I"
#endif