~ubuntu-branches/ubuntu/utopic/unrar-nonfree/utopic-updates

« back to all changes in this revision

Viewing changes to win32stm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chris Anderson
  • Date: 2004-07-02 01:53:47 UTC
  • Revision ID: james.westby@ubuntu.com-20040702015347-26ptn0errf3ew0u9
Tags: upstream-3.3.6
ImportĀ upstreamĀ versionĀ 3.3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
 
 
4
#ifndef SFX_MODULE
 
5
void ExtractStreams(Archive &Arc,char *FileName,wchar *FileNameW)
 
6
{
 
7
  if (!WinNT())
 
8
    return;
 
9
 
 
10
  if (Arc.HeaderCRC!=Arc.StreamHead.HeadCRC)
 
11
  {
 
12
#ifndef SILENT
 
13
    Log(Arc.FileName,St(MStreamBroken),FileName);
 
14
#endif
 
15
    ErrHandler.SetErrorCode(CRC_ERROR);
 
16
    return;
 
17
  }
 
18
 
 
19
  if (Arc.StreamHead.Method<0x31 || Arc.StreamHead.Method>0x35 || Arc.StreamHead.UnpVer>PACK_VER)
 
20
  {
 
21
#ifndef SILENT
 
22
    Log(Arc.FileName,St(MStreamUnknown),FileName);
 
23
#endif
 
24
    ErrHandler.SetErrorCode(WARNING);
 
25
    return;
 
26
  }
 
27
 
 
28
  char StreamName[NM+2];
 
29
  if (FileName[0]!=0 && FileName[1]==0)
 
30
  {
 
31
    strcpy(StreamName,".\\");
 
32
    strcpy(StreamName+2,FileName);
 
33
  }
 
34
  else
 
35
    strcpy(StreamName,FileName);
 
36
  if (strlen(StreamName)+strlen((char *)Arc.StreamHead.StreamName)>=sizeof(StreamName))
 
37
  {
 
38
#ifndef SILENT
 
39
    Log(Arc.FileName,St(MStreamBroken),FileName);
 
40
#endif
 
41
    ErrHandler.SetErrorCode(CRC_ERROR);
 
42
    return;
 
43
  }
 
44
 
 
45
  strcat(StreamName,(char *)Arc.StreamHead.StreamName);
 
46
 
 
47
  FindData fd;
 
48
  bool Found=FindFile::FastFind(FileName,FileNameW,&fd);
 
49
 
 
50
  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
 
51
    SetFileAttr(FileName,FileNameW,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
 
52
 
 
53
  File CurFile;
 
54
  if (CurFile.WCreate(StreamName))
 
55
  {
 
56
    ComprDataIO DataIO;
 
57
    Unpack Unpack(&DataIO);
 
58
    Unpack.Init();
 
59
 
 
60
    Array<unsigned char> UnpData(Arc.StreamHead.UnpSize);
 
61
    DataIO.SetPackedSizeToRead(Arc.StreamHead.DataSize);
 
62
    DataIO.EnableShowProgress(false);
 
63
    DataIO.SetFiles(&Arc,&CurFile);
 
64
    Unpack.SetDestSize(Arc.StreamHead.UnpSize);
 
65
    Unpack.DoUnpack(Arc.StreamHead.UnpVer,false);
 
66
 
 
67
    if (Arc.StreamHead.StreamCRC!=~DataIO.UnpFileCRC)
 
68
    {
 
69
#ifndef SILENT
 
70
      Log(Arc.FileName,St(MStreamBroken),StreamName);
 
71
#endif
 
72
      ErrHandler.SetErrorCode(CRC_ERROR);
 
73
    }
 
74
    else
 
75
      CurFile.Close();
 
76
  }
 
77
  File HostFile;
 
78
  if (Found && HostFile.Open(FileName,FileNameW,true,true))
 
79
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
 
80
                &fd.ftLastWriteTime);
 
81
  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
 
82
    SetFileAttr(FileName,FileNameW,fd.FileAttr);
 
83
}
 
84
#endif
 
85
 
 
86
 
 
87
void ExtractStreamsNew(Archive &Arc,char *FileName,wchar *FileNameW)
 
88
{
 
89
  if (!WinNT())
 
90
    return;
 
91
 
 
92
  wchar NameW[NM];
 
93
  if (FileNameW!=NULL && *FileNameW!=0)
 
94
    strcpyw(NameW,FileNameW);
 
95
  else
 
96
    CharToWide(FileName,NameW);
 
97
  wchar StreamNameW[NM+2];
 
98
  if (NameW[0]!=0 && NameW[1]==0)
 
99
  {
 
100
    strcpyw(StreamNameW,L".\\");
 
101
    strcpyw(StreamNameW+2,NameW);
 
102
  }
 
103
  else
 
104
    strcpyw(StreamNameW,NameW);
 
105
 
 
106
  wchar *DestName=StreamNameW+strlenw(StreamNameW);
 
107
  byte *SrcName=&Arc.SubHead.SubData[0];
 
108
  int DestSize=Arc.SubHead.SubData.Size()/2;
 
109
 
 
110
  if (strlenw(StreamNameW)+DestSize>=sizeof(StreamNameW)/sizeof(StreamNameW[0]))
 
111
  {
 
112
#if !defined(SILENT) && !defined(SFX_MODULE)
 
113
    Log(Arc.FileName,St(MStreamBroken),FileName);
 
114
#endif
 
115
    ErrHandler.SetErrorCode(CRC_ERROR);
 
116
    return;
 
117
  }
 
118
 
 
119
  RawToWide(SrcName,DestName,DestSize);
 
120
  DestName[DestSize]=0;
 
121
 
 
122
  FindData fd;
 
123
  bool Found=FindFile::FastFind(FileName,FileNameW,&fd);
 
124
 
 
125
  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
 
126
    SetFileAttr(FileName,FileNameW,fd.FileAttr & ~FILE_ATTRIBUTE_READONLY);
 
127
  char StreamName[NM];
 
128
  WideToChar(StreamNameW,StreamName);
 
129
  File CurFile;
 
130
  if (CurFile.WCreate(StreamName,StreamNameW) && Arc.ReadSubData(NULL,&CurFile))
 
131
    CurFile.Close();
 
132
  File HostFile;
 
133
  if (Found && HostFile.Open(FileName,FileNameW,true,true))
 
134
    SetFileTime(HostFile.GetHandle(),&fd.ftCreationTime,&fd.ftLastAccessTime,
 
135
                &fd.ftLastWriteTime);
 
136
  if (fd.FileAttr & FILE_ATTRIBUTE_READONLY)
 
137
    SetFileAttr(FileName,FileNameW,fd.FileAttr);
 
138
}