~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to errhnd.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "rar.hpp"
2
2
 
3
 
 
4
3
ErrorHandler::ErrorHandler()
5
4
{
6
5
  Clean();
22
21
void ErrorHandler::MemoryError()
23
22
{
24
23
  MemoryErrorMsg();
25
 
  Throw(RARX_MEMORY);
 
24
  Exit(RARX_MEMORY);
26
25
}
27
26
 
28
27
 
30
29
{
31
30
#ifndef SILENT
32
31
  OpenErrorMsg(FileName);
33
 
  Throw(RARX_OPEN);
 
32
  Exit(RARX_OPEN);
34
33
#endif
35
34
}
36
35
 
37
36
 
38
37
void ErrorHandler::CloseError(const wchar *FileName)
39
38
{
40
 
#ifndef SILENT
41
39
  if (!UserBreak)
42
40
  {
43
 
    Log(NULL,St(MErrFClose),FileName);
 
41
    uiMsg(UIERROR_FILECLOSE,FileName);
44
42
    SysErrMsg();
45
43
  }
46
 
#endif
47
44
#if !defined(SILENT) || defined(RARDLL)
48
 
  Throw(RARX_FATAL);
 
45
  Exit(RARX_FATAL);
49
46
#endif
50
47
}
51
48
 
56
53
  ReadErrorMsg(FileName);
57
54
#endif
58
55
#if !defined(SILENT) || defined(RARDLL)
59
 
  Throw(RARX_FATAL);
 
56
  Exit(RARX_FATAL);
60
57
#endif
61
58
}
62
59
 
67
64
  if (!Silent)
68
65
  {
69
66
    SysErrMsg();
70
 
    mprintf(L"\n");
71
 
    Log(NULL,St(MErrRead),FileName);
72
 
    return Ask(St(MRetryAbort))==1;
 
67
    return uiAskRepeatRead(FileName);
73
68
  }
74
69
#endif
75
70
  return false;
82
77
  WriteErrorMsg(ArcName,FileName);
83
78
#endif
84
79
#if !defined(SILENT) || defined(RARDLL)
85
 
  Throw(RARX_WRITE);
 
80
  Exit(RARX_WRITE);
86
81
#endif
87
82
}
88
83
 
90
85
#ifdef _WIN_ALL
91
86
void ErrorHandler::WriteErrorFAT(const wchar *FileName)
92
87
{
93
 
#if !defined(SILENT) && !defined(SFX_MODULE)
94
88
  SysErrMsg();
95
 
  Log(NULL,St(MNTFSRequired),FileName);
96
 
#endif
 
89
  uiMsg(UIERROR_NTFSREQUIRED,FileName);
97
90
#if !defined(SILENT) && !defined(SFX_MODULE) || defined(RARDLL)
98
 
  Throw(RARX_WRITE);
 
91
  Exit(RARX_WRITE);
99
92
#endif
100
93
}
101
94
#endif
107
100
  if (!Silent)
108
101
  {
109
102
    SysErrMsg();
110
 
    mprintf(L"\n");
111
 
    Log(NULL,St(DiskFull ? MNotEnoughDisk:MErrWrite),FileName);
112
 
    return Ask(St(MRetryAbort))==1;
 
103
    return uiAskRepeatWrite(FileName,DiskFull);
113
104
  }
114
105
#endif
115
106
  return false;
118
109
 
119
110
void ErrorHandler::SeekError(const wchar *FileName)
120
111
{
121
 
#ifndef SILENT
122
112
  if (!UserBreak)
123
113
  {
124
 
    Log(NULL,St(MErrSeek),FileName);
 
114
    uiMsg(UIERROR_FILESEEK,FileName);
125
115
    SysErrMsg();
126
116
  }
127
 
#endif
128
117
#if !defined(SILENT) || defined(RARDLL)
129
 
  Throw(RARX_FATAL);
 
118
  Exit(RARX_FATAL);
130
119
#endif
131
120
}
132
121
 
136
125
  va_list arglist;
137
126
  va_start(arglist,fmt);
138
127
  wchar Msg[1024];
 
128
#ifdef _ANDROID
 
129
  // vswprintf does not work in Android NDK. Conversion below should be ok
 
130
  // as long as we do not pass Unicode strings in arguments.
 
131
  char fmtA[NM],MsgA[ASIZE(Msg)];
 
132
  WideToChar(fmt,fmtA,ASIZE(fmtA));
 
133
  vsnprintf(MsgA,ASIZE(MsgA),fmtA,arglist);
 
134
  CharToWide(MsgA,Msg,ASIZE(Msg));
 
135
#else
139
136
  vswprintf(Msg,ASIZE(Msg),fmt,arglist);
140
 
#ifndef SILENT
141
 
  Log(NULL,L"%ls",Msg);
142
 
  mprintf(L"\n");
 
137
#endif
 
138
  uiMsg(UIERROR_GENERALERRMSG,Msg);
143
139
  SysErrMsg();
144
 
#endif
145
140
  va_end(arglist);
146
141
}
147
142
 
148
143
 
149
144
void ErrorHandler::MemoryErrorMsg()
150
145
{
151
 
#ifndef SILENT
152
 
  Log(NULL,St(MErrOutMem));
153
 
#endif
 
146
  uiMsg(UIERROR_MEMORY);
 
147
  SetErrorCode(RARX_MEMORY);
154
148
}
155
149
 
156
150
 
162
156
 
163
157
void ErrorHandler::OpenErrorMsg(const wchar *ArcName,const wchar *FileName)
164
158
{
165
 
#ifndef SILENT
166
 
  if (FileName!=NULL)
167
 
    Log(ArcName,St(MCannotOpen),FileName);
 
159
  uiMsg(UIERROR_FILEOPEN,ArcName,FileName);
168
160
  SysErrMsg();
169
 
#endif
 
161
  SetErrorCode(RARX_OPEN);
170
162
}
171
163
 
172
164
 
178
170
 
179
171
void ErrorHandler::CreateErrorMsg(const wchar *ArcName,const wchar *FileName)
180
172
{
181
 
#ifndef SILENT
182
 
  Log(ArcName,St(MCannotCreate),FileName);
183
 
 
184
 
#if defined(_WIN_ALL) && defined(MAX_PATH)
185
 
  CheckLongPathErrMsg(FileName);
186
 
#endif
187
 
 
 
173
  uiMsg(UIERROR_FILECREATE,ArcName,FileName);
188
174
  SysErrMsg();
189
 
#endif
190
 
}
191
 
 
192
 
 
193
 
// Check the path length and display the error message if it is too long.
194
 
void ErrorHandler::CheckLongPathErrMsg(const wchar *FileName)
195
 
{
196
 
#if defined(_WIN_ALL) && !defined (SILENT) && defined(MAX_PATH)
197
 
  if (GetLastError()==ERROR_PATH_NOT_FOUND)
198
 
  {
199
 
    size_t NameLength=wcslen(FileName);
200
 
    if (!IsFullPath(FileName))
201
 
    {
202
 
      wchar CurDir[NM];
203
 
      GetCurrentDirectory(ASIZE(CurDir),CurDir);
204
 
      NameLength+=wcslen(CurDir)+1;
205
 
    }
206
 
    if (NameLength>MAX_PATH)
207
 
    {
208
 
      Log(NULL,St(MMaxPathLimit),MAX_PATH);
209
 
    }
210
 
  }
211
 
#endif
 
175
  SetErrorCode(RARX_CREATE);
212
176
}
213
177
 
214
178
 
220
184
 
221
185
void ErrorHandler::ReadErrorMsg(const wchar *ArcName,const wchar *FileName)
222
186
{
223
 
#ifndef SILENT
224
 
  Log(ArcName,St(MErrRead),FileName);
 
187
  uiMsg(UIERROR_FILEREAD,ArcName,FileName);
225
188
  SysErrMsg();
226
 
#endif
 
189
  SetErrorCode(RARX_FATAL);
227
190
}
228
191
 
229
192
 
230
193
void ErrorHandler::WriteErrorMsg(const wchar *ArcName,const wchar *FileName)
231
194
{
232
 
#ifndef SILENT
233
 
  Log(ArcName,St(MErrWrite),FileName);
 
195
  uiMsg(UIERROR_FILEWRITE,ArcName,FileName);
234
196
  SysErrMsg();
235
 
#endif
 
197
  SetErrorCode(RARX_WRITE);
 
198
}
 
199
 
 
200
 
 
201
void ErrorHandler::ArcBrokenMsg(const wchar *ArcName)
 
202
{
 
203
  uiMsg(UIERROR_ARCBROKEN,ArcName);
 
204
  SetErrorCode(RARX_CRC);
 
205
}
 
206
 
 
207
 
 
208
void ErrorHandler::ChecksumFailedMsg(const wchar *ArcName,const wchar *FileName)
 
209
{
 
210
  uiMsg(UIERROR_CHECKSUM,ArcName,FileName);
 
211
  SetErrorCode(RARX_CRC);
 
212
}
 
213
 
 
214
 
 
215
void ErrorHandler::UnknownMethodMsg(const wchar *ArcName,const wchar *FileName)
 
216
{
 
217
  uiMsg(UIERROR_UNKNOWNMETHOD,ArcName,FileName);
 
218
  ErrHandler.SetErrorCode(RARX_FATAL);
236
219
}
237
220
 
238
221
 
239
222
void ErrorHandler::Exit(RAR_EXIT ExitCode)
240
223
{
241
224
#ifndef GUI
242
 
  Alarm();
 
225
  uiAlarm(UIALARM_ERROR);
243
226
#endif
244
227
  Throw(ExitCode);
245
228
}
254
237
      if (ExitCode==RARX_SUCCESS)
255
238
        ExitCode=Code;
256
239
      break;
 
240
    case RARX_CRC:
 
241
      if (ExitCode!=RARX_BADPWD)
 
242
        ExitCode=Code;
 
243
      break;
257
244
    case RARX_FATAL:
258
245
      if (ExitCode==RARX_SUCCESS || ExitCode==RARX_WARNING)
259
246
        ExitCode=RARX_FATAL;
320
307
#ifndef GUI
321
308
#ifdef _WIN_ALL
322
309
  SetConsoleCtrlHandler(Enable ? ProcessSignal:NULL,TRUE);
323
 
//  signal(SIGBREAK,Enable ? ProcessSignal:SIG_IGN);
324
310
#else
325
311
  signal(SIGINT,Enable ? ProcessSignal:SIG_IGN);
326
312
  signal(SIGTERM,Enable ? ProcessSignal:SIG_IGN);
338
324
  if (Code!=RARX_SUCCESS && Code!=RARX_USERERROR)
339
325
    mprintf(L"\n%s\n",St(MProgAborted));
340
326
#endif
341
 
  ErrHandler.SetErrorCode(Code);
 
327
  SetErrorCode(Code);
342
328
  throw Code;
343
329
}
344
330
 
368
354
        *EndMsg=0;
369
355
        EndMsg++;
370
356
      }
371
 
      Log(NULL,L"\n%ls",CurMsg);
 
357
      uiMsg(UIERROR_SYSERRMSG,CurMsg);
372
358
      CurMsg=EndMsg;
373
359
    }
374
360
  }
378
364
#if defined(_UNIX) || defined(_EMX)
379
365
  if (errno!=0)
380
366
  {
 
367
#ifdef _ANDROID
 
368
    // Android NDK sets errno to confusing "not a typewriter" ENOTTY code
 
369
    // after write error reported by write().
 
370
    if (errno == ENOTTY)
 
371
      return;
 
372
#endif
381
373
    char *err=strerror(errno);
382
374
    if (err!=NULL)
383
375
    {
384
 
      wchar MsgW[1024];
385
 
      CharToWide(err,MsgW,ASIZE(MsgW));
386
 
      Log(NULL,L"\n%s",MsgW);
 
376
      wchar Msg[1024];
 
377
      CharToWide(err,Msg,ASIZE(Msg));
 
378
      uiMsg(UIERROR_SYSERRMSG,Msg);
387
379
    }
388
380
  }
389
381
#endif