4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
24 #include "awindowgui.inc"
31 #include "filesystem.h"
32 #include "indexfile.h"
33 #include "mainsession.h"
34 #include "threadindexer.h"
37 Assets::Assets(EDL *edl) : List<Asset>()
47 int Assets::load(FileXML *file, uint32_t load_flags)
53 result = file->read_tag();
56 if(file->tag.title_is("/ASSETS"))
61 if(file->tag.title_is("ASSET"))
63 const char *path = file->tag.get_property("SRC");
64 if(path && path[0] != 0)
66 Asset *new_asset = new Asset(path);
67 new_asset->read(file);
68 Asset *asset = update(new_asset);
69 asset->copy_from(new_asset,1);
70 new_asset->Garbage::remove_user();
78 int Assets::save(FileXML *file, char *path)
80 file->tag.set_title("ASSETS");
82 file->append_newline();
84 for(Asset* current = first; current; current = NEXT)
91 file->tag.set_title("/ASSETS");
93 file->append_newline();
94 file->append_newline();
98 void Assets::copy_from(Assets *assets)
102 for(Asset *current = assets->first; current; current = NEXT)
105 append(new_asset = new Asset);
106 new_asset->copy_from(current, 1);
110 Assets& Assets::operator=(Assets &assets)
112 printf("Assets::operator= 1\n");
118 void Assets::update_index(Asset *asset)
121 for(Asset* current = first; current; current = NEXT)
123 if(current->test_path(asset->path))
125 current->update_index(asset);
130 Asset* Assets::update(Asset *asset)
134 for(Asset* current = first; current; current = NEXT)
136 // Asset already exists.
137 if(current->test_path(asset->path))
143 // Asset doesn't exist.
144 Asset *asset_copy = new Asset(*asset);
149 int Assets::delete_all()
158 Asset* Assets::update(const char *path)
160 Asset* current = first;
164 if(current->test_path(path))
171 return append(new Asset(path));
174 Asset* Assets::get_asset(const char *filename)
176 Asset* current = first;
181 //printf("Assets::get_asset %p %s\n", filename, filename);
182 if(current->test_path(filename))
187 current = current->next;
193 void Assets::remove_asset(Asset *asset)
195 remove_pointer(asset);
196 asset->Garbage::remove_user();
200 int Assets::number_of(Asset *asset)
205 for(i = 0, current = first; current && current != asset; i++, current = NEXT)
211 Asset* Assets::asset_number(int number)
216 for(i = 0, current = first; i < number && current; i++, current = NEXT)
222 int Assets::update_old_filename(char *old_filename, char *new_filename)
224 for(Asset* current = first; current; current = NEXT)
226 if(!strcmp(current->path, old_filename))
228 current->update_path(new_filename);
235 int Assets::dump(FILE *fp)
237 for(Asset *current = first; current; current = NEXT)