1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/main.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
25 //#define SYNFIG_NO_ANGLE
42 #include <ETL/stringf>
43 #include "listimporter.h"
48 #include "valuenode.h"
51 #include "loadcanvas.h"
69 using namespace synfig;
71 /* === M A C R O S ========================================================= */
73 #define MODULE_LIST_FILENAME "synfig_modules.cfg"
75 /* === S T A T I C S ======================================================= */
77 static etl::reference_counter synfig_ref_count_(0);
79 /* === P R O C E D U R E S ================================================= */
81 /* === M E T H O D S ======================================================= */
101 synfig::get_build_date()
107 synfig::get_build_time()
112 extern const char *get_build_time();
115 synfig::check_version_(int version,int vec_size, int color_size,int canvas_size,int layer_size)
121 if(version!=SYNFIG_LIBRARY_VERSION)
123 synfig::error(_("API Version mismatch (LIB:%d, PROG:%d)"),SYNFIG_LIBRARY_VERSION,version);
126 if(vec_size!=sizeof(Vector))
128 synfig::error(_("Size of Vector mismatch (app:%d, lib:%d)"),vec_size,sizeof(Vector));
131 if(color_size!=sizeof(Color))
133 synfig::error(_("Size of Color mismatch (app:%d, lib:%d)"),color_size,sizeof(Color));
136 if(canvas_size!=sizeof(Canvas))
138 synfig::error(_("Size of Canvas mismatch (app:%d, lib:%d)"),canvas_size,sizeof(Canvas));
141 if(layer_size!=sizeof(Layer))
143 synfig::error(_("Size of Layer mismatch (app:%d, lib:%d)"),layer_size,sizeof(Layer));
150 static void broken_pipe_signal (int /*sig*/) {
151 synfig::warning("Broken Pipe...");
154 bool retrieve_modules_to_load(String filename,std::list<String> &modules_to_load)
156 if(filename=="standard")
160 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_bmp")==modules_to_load.end())
161 modules_to_load.push_back("trgt_bmp");
162 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_gif")==modules_to_load.end())
163 modules_to_load.push_back("trgt_gif");
164 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_dv")==modules_to_load.end())
165 modules_to_load.push_back("trgt_dv");
166 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_ffmpeg")==modules_to_load.end())
167 modules_to_load.push_back("mod_ffmpeg");
168 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_imagemagick")==modules_to_load.end())
169 modules_to_load.push_back("mod_imagemagick");
170 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_std")==modules_to_load.end())
171 modules_to_load.push_back("lyr_std");
172 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_freetype")==modules_to_load.end())
173 modules_to_load.push_back("lyr_freetype");
175 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_png")==modules_to_load.end())
176 modules_to_load.push_back("trgt_png");
179 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_openexr")==modules_to_load.end())
180 modules_to_load.push_back("mod_openexr");
186 std::ifstream file(filename.c_str());
189 // warning("Cannot open "+filename);
195 getline(file,modulename);
196 if(!modulename.empty() && find(modules_to_load.begin(),modules_to_load.end(),modulename)==modules_to_load.end())
197 modules_to_load.push_back(modulename);
210 synfig::Main::Main(const synfig::String& basepath,ProgressCallback *cb):
211 ref_count_(synfig_ref_count_)
213 if(ref_count_.count())
216 synfig_ref_count_.reset();
217 ref_count_=synfig_ref_count_;
219 // Add initialization after this point
224 String prefix=basepath+"/..";
227 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
230 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
231 signal(SIGPIPE, broken_pipe_signal);
234 //_config_search_path=new vector"string.h"();
236 // Init the subsystems
237 if(cb)cb->amount_complete(0, 100);
238 if(cb)cb->task(_("Starting Subsystem \"Modules\""));
239 if(!Module::subsys_init(prefix))
240 throw std::runtime_error(_("Unable to initialize subsystem \"Module\""));
242 if(cb)cb->task(_("Starting Subsystem \"Layers\""));
243 if(!Layer::subsys_init())
245 Module::subsys_stop();
246 throw std::runtime_error(_("Unable to initialize subsystem \"Layers\""));
249 if(cb)cb->task(_("Starting Subsystem \"Targets\""));
250 if(!Target::subsys_init())
252 Layer::subsys_stop();
253 Module::subsys_stop();
254 throw std::runtime_error(_("Unable to initialize subsystem \"Targets\""));
257 if(cb)cb->task(_("Starting Subsystem \"Importers\""));
258 if(!Importer::subsys_init())
260 Target::subsys_stop();
261 Layer::subsys_stop();
262 Module::subsys_stop();
263 throw std::runtime_error(_("Unable to initialize subsystem \"Importers\""));
266 if(cb)cb->task(_("Starting Subsystem \"ValueNodes\""));
267 if(!ValueNode::subsys_init())
269 Importer::subsys_stop();
270 Target::subsys_stop();
271 Layer::subsys_stop();
272 Module::subsys_stop();
273 throw std::runtime_error(_("Unable to initialize subsystem \"ValueNodes\""));
276 // Load up the list importer
277 Importer::book()[String("lst")]=ListImporter::create;
281 // Load up the modules
282 std::list<String> modules_to_load;
283 std::vector<String> locations;
285 if(!getenv("SYNFIG_MODULE_LIST"))
287 locations.push_back("standard");
288 locations.push_back("./"MODULE_LIST_FILENAME); //1
289 locations.push_back("../etc/"MODULE_LIST_FILENAME); //1
290 locations.push_back("~/.synfig/"MODULE_LIST_FILENAME); //2
291 locations.push_back(prefix+"/etc/"+MODULE_LIST_FILENAME); //3
292 locations.push_back("/usr/local/etc/"MODULE_LIST_FILENAME);
294 locations.push_back(SYSCONFDIR"/"MODULE_LIST_FILENAME);
297 locations.push_back("/Library/Frameworks/synfig.framework/Resources/"MODULE_LIST_FILENAME);
298 locations.push_back("/Library/Synfig/"MODULE_LIST_FILENAME);
299 locations.push_back("~/Library/Synfig/"MODULE_LIST_FILENAME);
302 locations.push_back("C:\\Program Files\\Synfig\\etc\\"MODULE_LIST_FILENAME);
307 locations.push_back(getenv("SYNFIG_MODULE_LIST"));
310 const char *locations[]=
313 "./"MODULE_LIST_FILENAME, //1
314 "../etc/"MODULE_LIST_FILENAME, //1
315 "~/.synfig/"MODULE_LIST_FILENAME, //2
316 "/usr/local/lib/synfig/modules/"MODULE_LIST_FILENAME, //3
317 "/usr/local/etc/"MODULE_LIST_FILENAME,
319 SYSCONFDIR"/"MODULE_LIST_FILENAME,
322 "/Library/Frameworks/synfig.framework/Resources/"MODULE_LIST_FILENAME,
323 "/Library/SYNFIG/"MODULE_LIST_FILENAME,
324 "~/Library/SYNFIG/"MODULE_LIST_FILENAME,
327 "C:\\Program Files\\SYNFIG\\etc\\"MODULE_LIST_FILENAME,
332 for(i=0;i<locations.size();i++)
333 if(retrieve_modules_to_load(locations[i],modules_to_load))
334 if(cb)cb->task(strprintf(_("Loading modules from %s"),locations[i].c_str()));
336 std::list<String>::iterator iter;
338 for(i=0,iter=modules_to_load.begin();iter!=modules_to_load.end();++iter,i++)
340 Module::Register(*iter,cb);
341 if(cb)cb->amount_complete((i+1)*100,modules_to_load.size()*100);
349 if(cb)cb->amount_complete(100, 100);
350 if(cb)cb->task(_("DONE"));
353 synfig::Main::~Main()
356 if(!synfig_ref_count_.unique())
358 synfig_ref_count_.detach();
360 // Add deinitialization after this point
362 if(get_open_canvas_map().size())
364 synfig::warning("Canvases still open!");
365 std::map<synfig::String, etl::loose_handle<Canvas> >::iterator iter;
366 for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter)
368 synfig::warning("%s: count()=%d",iter->first.c_str(), iter->second.count());
372 ValueNode::subsys_stop();
373 Importer::subsys_stop();
374 Target::subsys_stop();
375 Layer::subsys_stop();
377 /*! \fixme For some reason, uncommenting the next
378 ** line will cause things to crash. This needs to be
379 ** looked into at some point. */
380 //Module::subsys_stop();
382 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
383 signal(SIGPIPE, SIG_DFL);
396 synfig::error(const char *format,...)
399 va_start(args,format);
400 error(vstrprintf(format,args));
404 synfig::error(const String &str)
406 static Mutex mutex; Mutex::Lock lock(mutex);
407 cerr<<"synfig("<<getpid()<<"): "<<_("error")<<": "+str<<endl;
411 synfig::warning(const char *format,...)
414 va_start(args,format);
415 warning(vstrprintf(format,args));
419 synfig::warning(const String &str)
421 static Mutex mutex; Mutex::Lock lock(mutex);
422 cerr<<"synfig("<<getpid()<<"): "<<_("warning")<<": "+str<<endl;
426 synfig::info(const char *format,...)
429 va_start(args,format);
430 info(vstrprintf(format,args));
434 synfig::info(const String &str)
436 static Mutex mutex; Mutex::Lock lock(mutex);
437 cerr<<"synfig("<<getpid()<<"): "<<_("info")<<": "+str<<endl;