Enlarge the Options buffer.
[reactos.git] / reactos / tools / cabman / dfp.cxx
index a7ca2d8..a48934c 100755 (executable)
@@ -78,6 +78,8 @@ CDFParser::CDFParser()
 
     InfModeEnabled = false;
     InfFileHandle = NULL;
+    
+    strcpy(FileRelativePath, "");
 }
 
 CDFParser::~CDFParser()
@@ -329,8 +331,8 @@ unsigned long CDFParser::Parse()
                     } else {
                         /* File copy */
                         Status = PerformFileCopy();
-    
-                        if (Status == CAB_STATUS_FAILURE) {
+
+                        if (Status != CAB_STATUS_SUCCESS) {
                             printf("Directive file contains errors at line %d.\n", (unsigned int)CurrentLine);
                             DPRINT(MID_TRACE, ("Error while copying file.\n"));
                         }
@@ -385,6 +387,20 @@ unsigned long CDFParser::Parse()
 }
 
 
+void CDFParser::SetFileRelativePath(char* Path)
+/*
+ * FUNCTION: Sets path where files in the .dff is assumed relative to
+ * ARGUMENTS:
+ *    Path = Pointer to string with path
+ */
+{
+    strcpy(FileRelativePath, Path);
+    ConvertPath(FileRelativePath, false);
+    if (strlen(FileRelativePath) > 0)
+        NormalizePath(FileRelativePath, MAX_PATH);
+}
+
+
 bool CDFParser::OnDiskLabel(unsigned long Number, char* Label)
 /*
  * FUNCTION: Called when a disk needs a label
@@ -1000,10 +1016,13 @@ unsigned long CDFParser::PerformFileCopy()
     char SrcName[MAX_PATH];
     char DstName[MAX_PATH];
     char InfLine[MAX_PATH];
+    char Options[128];
+    char BaseFilename[MAX_PATH];
 
-    strcpy(SrcName, "");
-    strcpy(DstName, "");
+    *SrcName = '\0';
+    *DstName = '\0';
 
+    // source file
     i = CurrentChar;
     while ((i < LineLength) &&
         ((ch = Line[i]) != ' ') &&
@@ -1015,8 +1034,10 @@ unsigned long CDFParser::PerformFileCopy()
     CurrentString[i] = '\0';
     CurrentToken = TokenString;
     CurrentChar  = i + 1;
-    strcpy(SrcName, CurrentString);
+    strcpy(BaseFilename, CurrentString);
+    strcat(SrcName, BaseFilename);
 
+    // destination
     SkipSpaces();
 
     if (CurrentToken != TokenEnd) {
@@ -1034,6 +1055,24 @@ unsigned long CDFParser::PerformFileCopy()
         strcpy(DstName, CurrentString);
     }
 
+    // options (it may be empty)
+    SkipSpaces ();
+
+    if (CurrentToken != TokenEnd) {
+        j = strlen(CurrentString); i = 0;
+        while ((CurrentChar + i < LineLength) &&
+            ((ch = Line[CurrentChar + i]) != ' ') &&
+             (ch != 0x09) &&
+             (ch != ';')) {
+            CurrentString[j + i] = ch;
+            i++;
+        }
+        CurrentString[j + i] = '\0';
+        CurrentToken = TokenString;
+        CurrentChar += i + 1;
+        strcpy(Options, CurrentString);
+    }
+
     if (!CabinetCreated) {
 
         DPRINT(MID_TRACE, ("Creating cabinet.\n"));
@@ -1060,21 +1099,35 @@ unsigned long CDFParser::PerformFileCopy()
 
     DPRINT(MID_TRACE, ("Adding file: '%s'   destination: '%s'.\n", SrcName, DstName));
 
-    sprintf(InfLine, "%s=%s", GetFileName(SrcName), DstName);
-    WriteInfLine(InfLine);
-
     Status = AddFile(SrcName);
-    if (Status != CAB_STATUS_SUCCESS) {
-        if (Status == CAB_STATUS_CANNOT_OPEN)
-                   printf("File does not exist: %s.\n", SrcName);
-        else if (Status == CAB_STATUS_NOMEMORY)
-            printf("Insufficient memory to add file: %s.\n", SrcName);
-        else
-            printf("Cannot add file: %s (%lu).\n", SrcName, Status);
-        return Status;
+    if (Status == CAB_STATUS_CANNOT_OPEN) {
+           strcpy(SrcName, FileRelativePath);
+           strcat(SrcName, BaseFilename);
+       Status = AddFile(SrcName);
     }
-
-    return CAB_STATUS_SUCCESS;
+    switch (Status)
+    {
+    case CAB_STATUS_SUCCESS:
+        sprintf(InfLine, "%s=%s", GetFileName(SrcName), DstName);
+        WriteInfLine(InfLine);
+        break;
+    case CAB_STATUS_CANNOT_OPEN:
+       if (strstr(Options,"optional"))
+       {
+               Status = CAB_STATUS_SUCCESS;
+               printf("Optional file does not exist: %s.\n", SrcName);
+       } else {
+               printf("File does not exist: %s.\n", SrcName);
+       }
+        break;
+    case CAB_STATUS_NOMEMORY:
+        printf("Insufficient memory to add file: %s.\n", SrcName);
+        break;
+    default:
+        printf("Cannot add file: %s (%lu).\n", SrcName, Status);
+        break;
+    }
+    return Status;
 }