remove incorrectly named
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / assets.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "assets.h"
24 #include "awindowgui.inc"
25 #include "batch.h"
26 #include "cache.h"
27 #include "bchash.h"
28 #include "edl.h"
29 #include "file.h"
30 #include "filexml.h"
31 #include "filesystem.h"
32 #include "indexfile.h"
33 #include "mainsession.h"
34 #include "threadindexer.h"
35 #include <string.h>
36
37 Assets::Assets(EDL *edl) : List<Asset>()
38 {
39         this->edl = edl;
40 }
41
42 Assets::~Assets()
43 {
44         delete_all();
45 }
46
47 int Assets::load(FileXML *file, uint32_t load_flags)
48 {
49         int result = 0;
50
51         while(!result)
52         {
53                 result = file->read_tag();
54                 if(!result)
55                 {
56                         if(file->tag.title_is("/ASSETS"))
57                         {
58                                 result = 1;
59                         }
60                         else
61                         if(file->tag.title_is("ASSET"))
62                         {
63                                 const char *path = file->tag.get_property("SRC");
64                                 if(path && path[0] != 0)
65                                 {
66                                         Asset *new_asset = new Asset(path);
67                                         new_asset->read(file);
68                                         update(new_asset);
69                                         new_asset->Garbage::remove_user();
70                                 }
71                         }
72                 }
73         }
74         return 0;
75 }
76
77 int Assets::save(FileXML *file, char *path)
78 {
79         file->tag.set_title("ASSETS");
80         file->append_tag();
81         file->append_newline();
82
83         for(Asset* current = first; current; current = NEXT)
84         {
85                 current->write(file,
86                         0,
87                         path);
88         }
89
90         file->tag.set_title("/ASSETS");
91         file->append_tag();
92         file->append_newline();
93         file->append_newline();
94         return 0;
95 }
96
97 void Assets::copy_from(Assets *assets)
98 {
99         delete_all();
100
101         for(Asset *current = assets->first; current; current = NEXT)
102         {
103                 Asset *new_asset;
104                 append(new_asset = new Asset);
105                 new_asset->copy_from(current, 1);
106         }
107 }
108
109 void Assets::update_index(Asset *asset)
110 {
111         if(!asset) return;
112         for(Asset* current = first; current; current = NEXT)
113         {
114                 if(current->test_path(asset->path))
115                 {
116                         current->update_index(asset);
117                 }
118         }
119 }
120
121 Asset* Assets::update(Asset *asset)
122 {
123         if(!asset) return 0;
124
125         for(Asset* current = first; current; current = NEXT)
126         {
127 // Asset already exists.
128                 if(current->test_path(asset->path))
129                 {
130                         return current;
131                 }
132         }
133
134 // Asset doesn't exist.
135         Asset *asset_copy = new Asset(*asset);
136         append(asset_copy);
137         return asset_copy;
138 }
139
140 int Assets::delete_all()
141 {
142         while(first)
143         {
144                 remove_asset(first);
145         }
146         return 0;
147 }
148
149 Asset* Assets::update(const char *path)
150 {
151         Asset* current = first;
152
153         while(current)
154         {
155                 if(current->test_path(path))
156                 {
157                         return current;
158                 }
159                 current = NEXT;
160         }
161
162         return append(new Asset(path));
163 }
164
165 Asset* Assets::get_asset(const char *filename)
166 {
167         Asset* current = first;
168         Asset* result = 0;
169
170         while(current)
171         {
172 //printf("Assets::get_asset %p %s\n", filename, filename);
173                 if(current->test_path(filename))
174                 {
175                         result = current;
176                         break;
177                 }
178                 current = current->next;
179         }
180
181         return result;
182 }
183
184 void Assets::remove_asset(Asset *asset)
185 {
186         remove_pointer(asset);
187         asset->Garbage::remove_user();
188 }
189
190
191 int Assets::number_of(Asset *asset)
192 {
193         int i;
194         Asset *current;
195
196         for(i = 0, current = first; current && current != asset; i++, current = NEXT)
197                 ;
198
199         return i;
200 }
201
202 Asset* Assets::asset_number(int number)
203 {
204         int i;
205         Asset *current;
206
207         for(i = 0, current = first; i < number && current; i++, current = NEXT)
208                 ;
209
210         return current;
211 }
212
213 int Assets::update_old_filename(char *old_filename, char *new_filename)
214 {
215         for(Asset* current = first; current; current = NEXT)
216         {
217                 if(!strcmp(current->path, old_filename))
218                 {
219                         current->update_path(new_filename);
220                 }
221         }
222         return 0;
223 }
224
225
226 int Assets::dump(FILE *fp)
227 {
228         for(Asset *current = first; current; current = NEXT)
229         {
230                 current->dump(fp);
231         }
232         return 0;
233 }
234
235