source: golgotha/src/golg/drive_map.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.6 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "file/file_man.hh"
10#include "string/string.hh"
11
12class g1_drive_map : public i4_file_manager_class
13
14  i4_str *sub, *replace_with;
15
16public:
17  i4_str *get(const i4_const_str &s)
18  {
19    i4_const_str::iterator i=s.strstr(*sub);   
20    if (i!=s.end())
21    {
22      int rlen=s.length() + replace_with->length();
23      i4_str *ret= new i4_str(s, rlen);
24
25      i4_str::iterator start=ret->begin();     
26      start+=s.ptr_diff(s.begin(), i);
27     
28      i4_str::iterator end=start;
29      end+=sub->length();
30
31      ret->remove(start, end);
32      ret->insert(start, *replace_with);
33     
34      return ret;
35    }   
36    else return 0;
37  }
38 
39
40  g1_drive_map(const i4_const_str &sub_path, const i4_const_str &replace_with)
41    : sub(new i4_str(sub_path)),
42      replace_with(new i4_str(replace_with))
43  {
44
45  }
46
47  ~g1_drive_map()
48  {
49    delete sub;
50    delete replace_with;
51  }
52
53  virtual i4_bool unlink(const i4_const_str &name)
54  {   
55    i4_str *s=get(name);
56    if (s)
57    {
58      i4_bool ret=next->unlink(*s);
59      delete s;
60      return ret;
61    }
62    else
63      return i4_F;
64  }
65
66  virtual i4_file_class *open(const i4_const_str &name, w32 flags)
67  {
68    i4_str *s=get(name);
69    if (s)
70    {
71      i4_file_class *ret=next->open(*s, flags);
72      delete s;
73      return ret;
74    }
75    else
76      return 0;
77  }
78
79  i4_bool get_status(const i4_const_str &filename,
80                             i4_file_status_struct &return_stat)
81  {
82    i4_str *s=get(filename);
83    if (s)
84    {
85      i4_bool ret=next->get_status(*s, return_stat);
86      delete s;
87      return ret;
88    }
89    else
90      return i4_F;
91  }
92
93  i4_bool mkdir(const i4_const_str &name)
94  {
95    i4_str *s=get(name);
96    if (s)
97    {
98      i4_bool ret=next->mkdir(*s);
99      delete s;
100      return ret;
101    }
102    else
103      return i4_F;
104  }
105
106  virtual i4_bool get_directory(const i4_const_str &path,
107                                i4_str **&files, w32 &tfiles,
108                                i4_str **&dirs, w32 &tdirs,
109                                        i4_file_status_struct **file_status)
110  {
111    i4_str *s=get(path);
112    if (s)
113    {
114      i4_bool ret=next->get_directory(*s, files, tfiles, dirs, tdirs, file_status);
115      delete s;
116      return ret;
117    }
118    else
119      return i4_F;
120  }
121} ;
122
123
124
125
126class g1_drive_map_init : public i4_init_class
127{
128  g1_drive_map *x, *X, *c, *alpha1;
129
130public:
131  int init_type() { return I4_INIT_TYPE_FILE_MANAGER; }
132
133  void init()
134  {
135    x=new g1_drive_map(i4_const_str("x:/"), i4_const_str("/u/"));
136    i4_add_file_manager(x, i4_T);
137
138    X=new g1_drive_map(i4_const_str("X:/"), i4_const_str("/u/"));
139    i4_add_file_manager(X, i4_T);
140
141    c=new g1_drive_map(i4_const_str("c:/tmp/"), i4_const_str("/tmp/"));
142    i4_add_file_manager(c, i4_T);
143
144    alpha1=new g1_drive_map(i4_const_str("//alpha1/"), i4_const_str("/u/"));
145    i4_add_file_manager(alpha1, i4_T);
146  }
147
148  void uninit()
149  {
150    i4_remove_file_manger(x);
151    i4_remove_file_manger(X);
152    i4_remove_file_manger(c);
153    i4_remove_file_manger(alpha1);
154  }
155
156} g1_drive_map_init_instance;
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Note: See TracBrowser for help on using the repository browser.