private void SaveNdfbinExecute(object obj)
        {
            Dispatcher      dispatcher = Dispatcher.CurrentDispatcher;
            Action <string> report     = msg => StatusText = msg;

            var s = new Task(() =>
            {
                try
                {
                    dispatcher.Invoke(() => IsUIBusy = true);
                    dispatcher.Invoke(report, string.Format("Saving back changes..."));

                    var writer     = new NdfbinWriter();
                    byte[] newFile = writer.Write(NdfBinary, NdfBinary.Header.IsCompressedBody);
                    dispatcher.Invoke(report, string.Format("Recompiling of {0} finished! ", EdataFileViewModel.EdataManager.FilePath));

                    EdataFileViewModel.EdataManager.ReplaceFile(OwnerFile, newFile);
                    dispatcher.Invoke(report, "Replacing new File in edata finished!");

                    EdataFileViewModel.LoadFile(EdataFileViewModel.LoadedFile);

                    EdataContentFile newOwen = EdataFileViewModel.EdataManager.Files.Single(x => x.Path == OwnerFile.Path);

                    OwnerFile = newOwen;
                    dispatcher.Invoke(report, string.Format("Saving of changes finished! {0}", EdataFileViewModel.EdataManager.FilePath));
                }
                catch (Exception ex)
                {
                    Trace.TraceError(string.Format("Error while saving Ndfbin file: {0}", ex));
                    dispatcher.Invoke(report, "Saving interrupted - Did you start Wargame before I was ready?");
                }
                finally
                {
                    dispatcher.Invoke(() => IsUIBusy = false);
                }
            });

            s.Start();
        }
        public byte[] Write(ScenarioFile file)
        {
            var scenarioData = new List <byte>();

            scenarioData.AddRange(Encoding.ASCII.GetBytes("SCENARIO\r\n"));
            scenarioData.AddRange(BitConverter.GetBytes(Version));
            scenarioData.AddRange(BitConverter.GetBytes(file.ContentFiles.Count));

            file.ContentFiles[0] = CreateAreaSubFile(file.ZoneData);

            var ndfBinWriter = new NdfbinWriter();

            file.ContentFiles[1] = ndfBinWriter.Write(file.NdfBinary, false); // something wrong here; enohka: Should be fixed by now?


            foreach (var contentFile in file.ContentFiles)
            {
                int padding = Utils.RoundToNextDivBy4(contentFile.Length) - contentFile.Length;

                scenarioData.AddRange(BitConverter.GetBytes(contentFile.Length + padding));
                scenarioData.AddRange(contentFile);

                var paddingLst = new List <byte>();

                for (int p = 0; p < padding; p++)
                {
                    paddingLst.Add(0x0);
                }

                scenarioData.AddRange(paddingLst);
            }

            byte[] hash = MD5.Create().ComputeHash(scenarioData.ToArray());

            scenarioData.InsertRange(10, hash.Concat(new byte[] { 0x00, 0x00 }));

            return(scenarioData.ToArray());
        }