1 /***************************************************************************
2 Try to display interesting crash dump
3
4 copyright : (C) 2007 by mean, (C) 2007 Gruntster
5 email : fixounet@free.fr
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17
18 #include <string>
19 #include "ADM_cpp.h"
20 #include "ADM_default.h"
21 #include "DIA_coreToolkit.h"
22 #include "ADM_edit.hxx"
23 #include "A_functions.h"
24 #include "../ADM_script2/include/ADM_script.h"
25
26 extern ADM_Composer *video_body;
27
28 #define CRASH_FILE "crash.py"
29
30 void saveCrashProject(void);
31
32 /**
33 \fn saveCrashProject
34 \brief Try to save the current project, useful in case of crash
35 */
saveCrashProject(void)36 void saveCrashProject(void)
37 {
38 const char *baseDir=ADM_getBaseDir();
39 const char *name=CRASH_FILE;
40 static int crashCount=0;
41 if(crashCount) return ; // avoid endless looping
42 crashCount++;
43 char *where=new char[strlen(baseDir)+strlen(name)+2];
44 strcpy(where,baseDir);
45 strcat(where,name);
46 printf("Saving crash file to %s\n",where);
47
48 A_saveScript(getScriptEngines()[0], where);
49
50 delete[] where;
51 }
52 /**
53 \fn checkCrashFile
54 \brief Check if there i a crash file
55 */
56
checkCrashFile(void)57 void checkCrashFile(void)
58 {
59 const char *baseDir=ADM_getBaseDir();
60 const char *name=CRASH_FILE;
61 static int crashCount=0;
62 char *where=new char[strlen(baseDir)+strlen(name)+2];
63 strcpy(where,baseDir);
64 strcat(where,name);
65
66 #if 1
67 uint32_t nbFile;
68 char *files[20];
69
70 if(buildDirectoryContent(&nbFile, baseDir, files, 20, "py"))
71 {
72 for(int i=0;i<nbFile;i++) printf("%d : %s\n",i,files[i]);
73 clearDirectoryContent(nbFile,files);
74 }
75 #endif
76
77
78 if(ADM_fileExist(where))
79 {
80 IScriptEngine *engine = getDefaultScriptEngine();
81
82 if (engine != NULL)
83 {
84 if(GUI_Confirmation_HIG(QT_TRANSLATE_NOOP("crash","Load it"),QT_TRANSLATE_NOOP("crash","Crash file"),
85 QT_TRANSLATE_NOOP("crash","I have detected a crash file. \nDo you want to load it ?\n(It will be deleted in all cases, you should save it if you want to keep it)")))
86 {
87 A_parseScript(engine,where);
88 A_Resync();
89 }
90 }
91 if(!ADM_eraseFile(where))
92 ADM_warning("Could not delete %s\n",where);
93 }else
94 {
95 printf("No crash file (%s)\n",where);
96 }
97 delete [] where;
98 }
99 //EOF
100