summaryrefslogtreecommitdiffstats
path: root/src/qmainrec.cpp
blob: 401a5015e9812e7f7504844cdc50e83bdddb5889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*

    File: qmainrec.c

    Copyright (C) 1998-2013 Christophe GRENIER <grenier@cgsecurity.org>

    This software is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write the Free Software Foundation, Inc., 51
    Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <QApplication>
#include <QTranslator>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "qphotorec.h"
#include "log.h"
#include "misc.h"
#include "dir.h"
#include "ext2_dir.h"
#include "ewf.h"
#include "file_jpg.h"
#include "ntfs_dir.h"

static void display_help(void)
{
  printf("\nUsage: qphotorec\n"\
      "       qphotorec /version\n" \
      "\n" \
      "QPhotoRec searches various file formats (JPEG, Office...), it stores them\n" \
      "in recup_dir directory.\n");
}

static void display_version(void)
{
  printf("QPhotoRec %s, Data Recovery Utility, %s\nChristophe GRENIER <grenier@cgsecurity.org>\nhttps://www.cgsecurity.org\n",VERSION,TESTDISKDATE);
  printf("\n");
  printf("Version: %s\n", VERSION);
  printf("Compiler: %s\n", get_compiler());
#ifdef RECORD_COMPILATION_DATE
  printf("Compilation date: %s\n", get_compilation_date());
#endif
  printf("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s\n",
      td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version());
  printf("OS: %s\n" , get_os());
}

int main(int argc, char *argv[])
{
  int log_errno=0;
  time_t my_time;
  int i;
  for(i=1; i<argc; i++)
  {
    if(strcmp(argv[i],"/help")==0 || strcmp(argv[i],"-help")==0 || strcmp(argv[i],"--help")==0 ||
      strcmp(argv[i],"/h")==0 || strcmp(argv[i],"-h")==0 ||
      strcmp(argv[i],"/?")==0 || strcmp(argv[i],"-?")==0)
    {
      display_help();
      return 0;
    }
    else if((strcmp(argv[i],"/version")==0) || (strcmp(argv[i],"-version")==0) || (strcmp(argv[i],"--version")==0) ||
      (strcmp(argv[i],"/v")==0) || (strcmp(argv[i],"-v")==0))
    {
      display_version();
      return 0;
    }
  }
#ifdef Q_WS_X11
  if(getenv("DISPLAY")==NULL)
  {
    printf("DISPLAY variable not set. Switching to PhotoRec in text mode.\n");
    if(execv("photorec", argv)<0)
    {
      printf("photorec failed: %s\n", strerror(errno));
    }
  }
#endif
  log_open("qphotorec.log", TD_LOG_CREATE, &log_errno);
  QApplication a(argc, argv);
  QTranslator translator;
  QString locale = QLocale::system().name().section('_', 0, 0);
  log_info("%s\n", locale.toStdString().c_str());
  if(translator.load(QLocale(), "qphotorec", ".", ":lang/", ".qm"))
  {
    a.installTranslator(&translator);
    log_info("translator installed\n");
  }
  else
  {
    log_info("translator not installed\n");
  }
  my_time=time(NULL);
  log_info("\n\n%s",ctime(&my_time));
  log_info("PhotoRec %s, Data Recovery Utility, %s\nChristophe GRENIER <grenier@cgsecurity.org>\nhttps://www.cgsecurity.org\n", VERSION, TESTDISKDATE);
  log_info("OS: %s\n" , get_os());
  log_info("Compiler: %s\n", get_compiler());
#ifdef RECORD_COMPILATION_DATE
  log_info("Compilation date: %s\n", get_compilation_date());
#endif
  log_info("ext2fs lib: %s, ntfs lib: %s, ewf lib: %s, libjpeg: %s\n",
      td_ext2fs_version(), td_ntfs_version(), td_ewf_version(), td_jpeg_version());

  QPhotorec *p = new QPhotorec();
  p->showMaximized();
  p->show();
  int ret=a.exec();
  delete p;
  log_info("QPhotoRec exited normally.\n");
  log_close();
  return ret;
}