Example #1
0
 /*
  * Insert the previously given values into the db table.
  * A warning will be printed and no data added if the given data doesn't
  * fit the db file's structure.
  */
 public override void Execute()
 {
     // insert always into packed files at the save to file
     foreach (PackedFile packed in PackedFiles)
     {
         // we'll read from packed, but that is in the source pack;
         // get or create the db file in the target pack
         DBFile targetFile = GetTargetFile(packed);
         foreach (RowValues insertValues in Source.Values)
         {
             if (targetFile.CurrentType.Fields.Count == insertValues.Count)
             {
                 DBRow newRow = targetFile.GetNewEntry();
                 for (int i = 0; i < newRow.Count; i++)
                 {
                     newRow[i].Value = insertValues[i];
                 }
                 targetFile.Entries.Add(newRow);
             }
             else
             {
                 Console.WriteLine("Cannot insert: was given {0} values, expecting {1} in {2}",
                                   insertValues.Count, targetFile.CurrentType.Fields.Count, packed.FullPath);
                 Console.WriteLine("Values: {0}", string.Join(",", insertValues));
             }
         }
         // encode and store in target pack
         PackedFile newPacked = new PackedFile(packed.FullPath, false);
         newPacked.Data = PackedFileDbCodec.GetCodec(newPacked).Encode(targetFile);
         SaveTo.Add(newPacked, true);
     }
 }
 public override void Execute()
 {
     if (SaveTo != null)
     {
         foreach (PackedFile packed in PackedFiles)
         {
             SaveTo.Add(packed, true);
         }
     }
 }
Example #3
0
 /*
  * Delete all entries matching the where clause if any was given,
  * or all entries if none was given.
  */
 public override void Execute()
 {
     if (SaveTo == null)
     {
         return;
     }
     foreach (PackedFile packed in PackedFiles)
     {
         PackedFile   result = new PackedFile(packed.FullPath, false);
         DBFile       dbFile = PackedFileDbCodec.Decode(packed);
         List <DBRow> kept   = new List <DBRow>();
         foreach (DBRow field in dbFile.Entries)
         {
             if (whereClause != null && !whereClause.Accept(field))
             {
                 kept.Add(field);
             }
         }
         DBFile newDbFile = new DBFile(dbFile.Header, dbFile.CurrentType);
         newDbFile.Entries.AddRange(kept);
         result.Data = PackedFileDbCodec.GetCodec(packed).Encode(newDbFile);
         SaveTo.Add(result, true);
     }
 }