1 /* === S Y N F I G ========================================================= */
2 /*! \file synfig/main.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
26 //#define SYNFIG_NO_ANGLE
43 #include <ETL/stringf>
44 #include "listimporter.h"
49 #include "valuenode.h"
52 #include "loadcanvas.h"
70 using namespace synfig;
72 /* === M A C R O S ========================================================= */
74 #define MODULE_LIST_FILENAME "synfig_modules.cfg"
76 /* === S T A T I C S ======================================================= */
78 static etl::reference_counter synfig_ref_count_(0);
80 /* === P R O C E D U R E S ================================================= */
82 /* === M E T H O D S ======================================================= */
102 synfig::get_build_date()
108 synfig::get_build_time()
113 extern const char *get_build_time();
116 synfig::check_version_(int version,int vec_size, int color_size,int canvas_size,int layer_size)
122 if(version!=SYNFIG_LIBRARY_VERSION)
124 synfig::error(_("API Version mismatch (LIB:%d, PROG:%d)"),SYNFIG_LIBRARY_VERSION,version);
127 if(vec_size!=sizeof(Vector))
129 synfig::error(_("Size of Vector mismatch (app:%d, lib:%d)"),vec_size,sizeof(Vector));
132 if(color_size!=sizeof(Color))
134 synfig::error(_("Size of Color mismatch (app:%d, lib:%d)"),color_size,sizeof(Color));
137 if(canvas_size!=sizeof(Canvas))
139 synfig::error(_("Size of Canvas mismatch (app:%d, lib:%d)"),canvas_size,sizeof(Canvas));
142 if(layer_size!=sizeof(Layer))
144 synfig::error(_("Size of Layer mismatch (app:%d, lib:%d)"),layer_size,sizeof(Layer));
151 static void broken_pipe_signal (int /*sig*/) {
152 synfig::warning("Broken Pipe...");
155 bool retrieve_modules_to_load(String filename,std::list<String> &modules_to_load)
157 if(filename=="standard")
161 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_bmp")==modules_to_load.end())
162 modules_to_load.push_back("trgt_bmp");
163 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_gif")==modules_to_load.end())
164 modules_to_load.push_back("trgt_gif");
165 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_dv")==modules_to_load.end())
166 modules_to_load.push_back("trgt_dv");
167 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_ffmpeg")==modules_to_load.end())
168 modules_to_load.push_back("mod_ffmpeg");
169 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_imagemagick")==modules_to_load.end())
170 modules_to_load.push_back("mod_imagemagick");
171 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_std")==modules_to_load.end())
172 modules_to_load.push_back("lyr_std");
173 if(find(modules_to_load.begin(),modules_to_load.end(),"lyr_freetype")==modules_to_load.end())
174 modules_to_load.push_back("lyr_freetype");
176 if(find(modules_to_load.begin(),modules_to_load.end(),"trgt_png")==modules_to_load.end())
177 modules_to_load.push_back("trgt_png");
180 if(find(modules_to_load.begin(),modules_to_load.end(),"mod_openexr")==modules_to_load.end())
181 modules_to_load.push_back("mod_openexr");
187 std::ifstream file(filename.c_str());
190 // warning("Cannot open "+filename);
196 getline(file,modulename);
197 if(!modulename.empty() && find(modules_to_load.begin(),modules_to_load.end(),modulename)==modules_to_load.end())
198 modules_to_load.push_back(modulename);
211 synfig::Main::Main(const synfig::String& basepath,ProgressCallback *cb):
212 ref_count_(synfig_ref_count_)
214 if(ref_count_.count())
217 synfig_ref_count_.reset();
218 ref_count_=synfig_ref_count_;
220 // Add initialization after this point
225 String prefix=basepath+"/..";
228 std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
231 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
232 signal(SIGPIPE, broken_pipe_signal);
235 //_config_search_path=new vector"string.h"();
237 // Init the subsystems
238 if(cb)cb->amount_complete(0, 100);
239 if(cb)cb->task(_("Starting Subsystem \"Modules\""));
240 if(!Module::subsys_init(prefix))
241 throw std::runtime_error(_("Unable to initialize subsystem \"Module\""));
243 if(cb)cb->task(_("Starting Subsystem \"Layers\""));
244 if(!Layer::subsys_init())
246 Module::subsys_stop();
247 throw std::runtime_error(_("Unable to initialize subsystem \"Layers\""));
250 if(cb)cb->task(_("Starting Subsystem \"Targets\""));
251 if(!Target::subsys_init())
253 Layer::subsys_stop();
254 Module::subsys_stop();
255 throw std::runtime_error(_("Unable to initialize subsystem \"Targets\""));
258 if(cb)cb->task(_("Starting Subsystem \"Importers\""));
259 if(!Importer::subsys_init())
261 Target::subsys_stop();
262 Layer::subsys_stop();
263 Module::subsys_stop();
264 throw std::runtime_error(_("Unable to initialize subsystem \"Importers\""));
267 if(cb)cb->task(_("Starting Subsystem \"ValueNodes\""));
268 if(!ValueNode::subsys_init())
270 Importer::subsys_stop();
271 Target::subsys_stop();
272 Layer::subsys_stop();
273 Module::subsys_stop();
274 throw std::runtime_error(_("Unable to initialize subsystem \"ValueNodes\""));
277 // Load up the list importer
278 Importer::book()[String("lst")]=ListImporter::create;
282 // Load up the modules
283 std::list<String> modules_to_load;
284 std::vector<String> locations;
286 if(!getenv("SYNFIG_MODULE_LIST"))
288 locations.push_back("standard");
289 locations.push_back("./"MODULE_LIST_FILENAME); //1
290 locations.push_back("../etc/"MODULE_LIST_FILENAME); //1
291 locations.push_back("~/.synfig/"MODULE_LIST_FILENAME); //2
292 locations.push_back(prefix+"/etc/"+MODULE_LIST_FILENAME); //3
293 locations.push_back("/usr/local/etc/"MODULE_LIST_FILENAME);
295 locations.push_back(SYSCONFDIR"/"MODULE_LIST_FILENAME);
298 locations.push_back("/Library/Frameworks/synfig.framework/Resources/"MODULE_LIST_FILENAME);
299 locations.push_back("/Library/Synfig/"MODULE_LIST_FILENAME);
300 locations.push_back("~/Library/Synfig/"MODULE_LIST_FILENAME);
303 locations.push_back("C:\\Program Files\\Synfig\\etc\\"MODULE_LIST_FILENAME);
308 locations.push_back(getenv("SYNFIG_MODULE_LIST"));
311 const char *locations[]=
314 "./"MODULE_LIST_FILENAME, //1
315 "../etc/"MODULE_LIST_FILENAME, //1
316 "~/.synfig/"MODULE_LIST_FILENAME, //2
317 "/usr/local/lib/synfig/modules/"MODULE_LIST_FILENAME, //3
318 "/usr/local/etc/"MODULE_LIST_FILENAME,
320 SYSCONFDIR"/"MODULE_LIST_FILENAME,
323 "/Library/Frameworks/synfig.framework/Resources/"MODULE_LIST_FILENAME,
324 "/Library/SYNFIG/"MODULE_LIST_FILENAME,
325 "~/Library/SYNFIG/"MODULE_LIST_FILENAME,
328 "C:\\Program Files\\SYNFIG\\etc\\"MODULE_LIST_FILENAME,
333 for(i=0;i<locations.size();i++)
334 if(retrieve_modules_to_load(locations[i],modules_to_load))
335 if(cb)cb->task(strprintf(_("Loading modules from %s"),locations[i].c_str()));
337 std::list<String>::iterator iter;
339 for(i=0,iter=modules_to_load.begin();iter!=modules_to_load.end();++iter,i++)
341 Module::Register(*iter,cb);
342 if(cb)cb->amount_complete((i+1)*100,modules_to_load.size()*100);
350 if(cb)cb->amount_complete(100, 100);
351 if(cb)cb->task(_("DONE"));
354 synfig::Main::~Main()
357 if(!synfig_ref_count_.unique())
359 synfig_ref_count_.detach();
361 // Add deinitialization after this point
363 if(get_open_canvas_map().size())
365 synfig::warning("Canvases still open!");
366 std::map<synfig::String, etl::loose_handle<Canvas> >::iterator iter;
367 for(iter=get_open_canvas_map().begin();iter!=get_open_canvas_map().end();++iter)
369 synfig::warning("%s: count()=%d",iter->first.c_str(), iter->second.count());
373 synfig::info("ValueNode::subsys_stop()");
374 ValueNode::subsys_stop();
375 synfig::info("Importer::subsys_stop()");
376 Importer::subsys_stop();
377 synfig::info("Target::subsys_stop()");
378 Target::subsys_stop();
379 synfig::info("Layer::subsys_stop()");
380 Layer::subsys_stop();
381 /*! \fixme For some reason, uncommenting the next line will cause things to crash.
382 This needs to be looked into at some point. */
383 // synfig::info("Module::subsys_stop()");
384 // Module::subsys_stop();
385 synfig::info("Exiting");
387 #if defined(HAVE_SIGNAL_H) && defined(SIGPIPE)
388 signal(SIGPIPE, SIG_DFL);
393 synfig::error(const char *format,...)
396 va_start(args,format);
397 error(vstrprintf(format,args));
401 synfig::error(const String &str)
403 static Mutex mutex; Mutex::Lock lock(mutex);
404 cerr<<"synfig("<<getpid()<<"): "<<_("error")<<": "+str<<endl;
408 synfig::warning(const char *format,...)
411 va_start(args,format);
412 warning(vstrprintf(format,args));
416 synfig::warning(const String &str)
418 static Mutex mutex; Mutex::Lock lock(mutex);
419 cerr<<"synfig("<<getpid()<<"): "<<_("warning")<<": "+str<<endl;
423 synfig::info(const char *format,...)
426 va_start(args,format);
427 info(vstrprintf(format,args));
431 synfig::info(const String &str)
433 static Mutex mutex; Mutex::Lock lock(mutex);
434 cerr<<"synfig("<<getpid()<<"): "<<_("info")<<": "+str<<endl;