Example #1
0
        /// <summary>
        /// Accepts a file bundle containing all data of files.
        /// </summary>
        /// <param name="data">Binary data.</param>
        /// <returns>List of events.</returns>
        public List <FileEvent> AcceptFileBundle(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
                using (ZipInputStream zip = new ZipInputStream(ms))
                {
                    ZipEntry block       = zip.GetNextEntry();
                    var      myPatchList = zip.ReadAllBytes().Deserialize <List <FileEvent> >();

                    while (true)
                    {
                        block = zip.GetNextEntry();
                        if (block == null)
                        {
                            break;
                        }

                        File.WriteAllBytes(Config.MetaFolderData.File(block.Name), zip.ReadAllBytes());
                    }

                    // Append versions
                    Dictionary <string, FileItem> myFileList = new Dictionary <string, FileItem>();
                    foreach (var item in VersionList.AllFiles)
                    {
                        myFileList[item.Id] = item;
                    }

                    foreach (var patch in myPatchList)
                    {
                        if (!myFileList.ContainsKey(patch.FileId))
                        {
                            myFileList[patch.FileId] = new FileItem(patch.FileId);
                            VersionList.AllFiles.Add(myFileList[patch.FileId]);
                            VersionList.SetFileByName(patch.Name, myFileList[patch.FileId]);
                        }

                        string oldName = myFileList[patch.FileId].CurrentName;
                        myFileList[patch.FileId].Merge(patch);
                        string currentName = myFileList[patch.FileId].CurrentName;
                        if (oldName != currentName)
                        {
                            VersionList.RemoveFileByName(oldName);
                            VersionList.SetFileByName(patch.Name, myFileList[patch.FileId]);
                        }
                    }

                    return(myPatchList);
                }
        }
Example #2
0
        public static void EnsureMtnIsExtracted()
        {
            if (!Directory.Exists(MtnPath))
            {
                Directory.CreateDirectory(MtnPath);
                Directory.CreateDirectory(FrameGrabsPath);


                string name   = "MtnFrameGrabProvider.mtn.zip";
                var    stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);

                using (var zip = new ZipInputStream(stream)) {
                    ZipEntry entry;
                    while ((entry = zip.GetNextEntry()) != null)
                    {
                        string destination = Path.Combine(MtnPath, entry.Name);
                        File.WriteAllBytes(destination, zip.ReadAllBytes());
                    }
                }
            }
        }
Example #3
0
        public static void EnsureMtnIsExtracted()
        {
            string name              = "MtnFrameGrabProvider.mtn.zip";
            var    stream            = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
            bool   needsToExtractMtn = false;

            /*
             * if (!Directory.Exists(MtnPath)) {
             *  Directory.CreateDirectory(MtnPath);
             *  //Directory.CreateDirectory(FrameGrabsPath);
             *
             *  using (var zip = new ZipInputStream(stream)) {
             *
             *      ZipEntry entry;
             *      while ((entry = zip.GetNextEntry()) != null) {
             *          string destination = Path.Combine(MtnPath, entry.Name);
             *          File.WriteAllBytes(destination, zip.ReadAllBytes());
             *      }
             *  }
             * } else {
             *  FileVersionInfo mtnVersion = FileVersionInfo.GetVersionInfo(MtnExe);
             *  Logger.ReportInfo("Using mtn version:{0}", mtnVersion.FileVersion);
             *  if (mtnVersion.FileVersion == null)
             *      Logger.ReportInfo("Using a pre-versioning copy of mtn.");
             * }
             */

            if (!Directory.Exists(MtnPath))
            {
                Directory.CreateDirectory(MtnPath);
                needsToExtractMtn = true;
            }
            else
            {
                FileVersionInfo mtnVersion = FileVersionInfo.GetVersionInfo(MtnExe);
                Logger.ReportInfo("Using mtn version:{0}", mtnVersion.FileVersion);

                if (mtnVersion.FileVersion != null)
                {
                    if (mtnVersion.FileVersion.ToString() != includedMtnVersion)
                    {
                        Logger.ReportInfo("mtn too old!");
                        needsToExtractMtn = true;
                    }
                }
                else
                {
                    Logger.ReportInfo("Using pre-versioning copy of mtn!");
                    needsToExtractMtn = true;
                }
            }

            if (needsToExtractMtn)
            {
                using (var zip = new ZipInputStream(stream))
                {
                    ZipEntry entry;
                    while ((entry = zip.GetNextEntry()) != null)
                    {
                        string destination = Path.Combine(MtnPath, entry.Name);
                        File.WriteAllBytes(destination, zip.ReadAllBytes());
                    }
                }
            }
        }