Exemple #1
0
        public void PasswordCheckingWithDateInExtraData()
        {
            MemoryStream ms = new MemoryStream();
            DateTime checkTime = new DateTime(2010, 10, 16, 0, 3, 28);

            using (ZipOutputStream zos = new ZipOutputStream(ms)) {
                zos.IsStreamOwner = false;
                zos.Password = "******";
                ZipEntry ze = new ZipEntry("uno");
                ze.DateTime = new DateTime(1998, 6, 5, 4, 3, 2);

                ZipExtraData zed = new ZipExtraData();

                zed.StartNewEntry();

                zed.AddData(1);

                TimeSpan delta = checkTime.ToUniversalTime() - new System.DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime();
                int seconds = (int)delta.TotalSeconds;
                zed.AddLeInt(seconds);
                zed.AddNewEntry(0x5455);

                ze.ExtraData = zed.GetEntryData();
                zos.PutNextEntry(ze);
                zos.WriteByte(54);
            }

            ms.Position = 0;
            using (ZipInputStream zis = new ZipInputStream(ms)) {
                zis.Password = "******";
                ZipEntry uno = zis.GetNextEntry();
                byte theByte = (byte)zis.ReadByte();
                Assert.AreEqual(54, theByte);
                Assert.AreEqual(-1, zis.ReadByte());
                Assert.AreEqual(checkTime, uno.DateTime);
            }
        }
Exemple #2
0
        public void ReadAndWriteZip64NonSeekable()
        {
            MemoryStream msw = new MemoryStreamWithoutSeek();
            using (ZipOutputStream outStream = new ZipOutputStream(msw))
            {
                outStream.UseZip64 = UseZip64.On;

                outStream.IsStreamOwner = false;
                outStream.PutNextEntry(new ZipEntry("StripedMarlin"));
                outStream.WriteByte(89);

                outStream.PutNextEntry(new ZipEntry("StripedMarlin2"));
                outStream.WriteByte(89);

                outStream.Close();
            }

            Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray()));

            msw.Position = 0;

            using (ZipInputStream zis = new ZipInputStream(msw))
            {
                while ( zis.GetNextEntry() != null )
                {
                    int len = 0;
                    int bufferSize = 1024;
                    byte[] buffer = new byte[bufferSize];
                    while ((len = zis.Read(buffer, 0, bufferSize)) > 0) {
                        // Reading the data is enough
                    }
                }
            }
        }
Exemple #3
0
        public void Zip64Descriptor()
        {
            MemoryStream msw = new MemoryStreamWithoutSeek();
            ZipOutputStream outStream = new ZipOutputStream(msw);
            outStream.UseZip64 = UseZip64.Off;

            outStream.IsStreamOwner = false;
            outStream.PutNextEntry(new ZipEntry("StripedMarlin"));
            outStream.WriteByte(89);
            outStream.Close();

            Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray()));

            msw = new MemoryStreamWithoutSeek();
            outStream = new ZipOutputStream(msw);
            outStream.UseZip64 = UseZip64.On;

            outStream.IsStreamOwner = false;
            outStream.PutNextEntry(new ZipEntry("StripedMarlin"));
            outStream.WriteByte(89);
            outStream.Close();

            Assert.IsTrue(ZipTesting.TestArchive(msw.ToArray()));
        }
        /// <summary>
        /// Adds the error report.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <remarks>Documented by Dev02, 2009-07-15</remarks>
        private static void AddErrorReport(ZipOutputStream stream, Exception exception)
        {
            #region collect data
            //fetch some information about ML
            Dictionary<string, string> mlInfos = new Dictionary<string, string>();
            mlInfos["MLVersion"] = AssemblyData.AssemblyVersion;
            mlInfos["MLPath"] = Application.StartupPath;
            mlInfos["MLOnStick"] = Setup.RunningFromStick().ToString();
            try
            {
                if (Dictionary != null)
                {
                    mlInfos["DatabaseType"] = Dictionary.DictionaryDAL.Parent.CurrentUser.ConnectionString.Typ.ToString();
                    if (Dictionary.IsDB)
                    {
                        mlInfos["DatabaseVersion"] = Dictionary.DictionaryDAL.Parent.CurrentUser.Database.DatabaseVersion.ToString();
                        List<string> versions = new List<string>();
                        foreach (DataLayerVersionInfo info in Dictionary.DictionaryDAL.Parent.CurrentUser.Database.SupportedDataLayerVersions)
                        {
                            string prefix = "";
                            switch (info.Type)
                            {
                                case VersionType.LowerBound:
                                    prefix = ">";
                                    break;
                                case VersionType.UpperBound:
                                    prefix = "<";
                                    break;
                                case VersionType.Equal:
                                default:
                                    break;
                            }
                            versions.Add(prefix + info.Version);
                        }
                        mlInfos["SupportedDataLayerVersions"] = String.Join(", ", versions.ToArray());
                        mlInfos["DatabaseUser"] = Dictionary.DictionaryDAL.Parent.CurrentUser.UserName;
                    }
                    mlInfos["DatabaseInfo"] = Dictionary.DictionaryDAL.Parent.CurrentUser.ConnectionString.ToString();
                    mlInfos["DictionaryDescription"] = Dictionary.Description;
                    mlInfos["DictionaryAuthor"] = Dictionary.Author;
                    mlInfos["DictionaryCategory"] = Dictionary.Category.ToString();
                    mlInfos["DictionaryPath"] = Dictionary.DictionaryPath;
                    mlInfos["DictionaryCardID"] = Dictionary.CurrentCard.ToString();
                    mlInfos["DictionaryCardCount"] = Dictionary.Cards.Cards.Count.ToString();
                    mlInfos["DictionaryChapterCount"] = Dictionary.Chapters.Chapters.Count.ToString();
                    mlInfos["DictionaryStyleSheetsUsed"] = Dictionary.UseDictionaryStyleSheets.ToString();
                    mlInfos["DictionaryQuestionStyleSheet"] = Dictionary.QuestionStyleSheet;
                    mlInfos["DictionaryAnswerStyleSheet"] = Dictionary.AnswerStyleSheet;
                }
                else
                {
                    mlInfos["Dictionary"] = "No dictionary open.";
                }
            }
            catch
            {
                mlInfos["Dictionary"] = "Readout failed.";
            }
            try
            {
                if (Dictionary != null && Dictionary.IsFileDB)
                {
                    mlInfos["DictionarySize"] = new FileInfo(Dictionary.DictionaryPath).Length.ToString() + " Bytes";
                    mlInfos["DictionaryFileAttributes"] = new FileInfo(Dictionary.DictionaryPath).Attributes.ToString();
                    mlInfos["DictionaryACL"] = new FileInfo(Dictionary.DictionaryPath).GetAccessControl().GetSecurityDescriptorSddlForm(System.Security.AccessControl.AccessControlSections.All);
                }
                mlInfos["LoggedinUser"] = string.Format("{0} - {1}", Environment.UserName, new System.Security.Principal.NTAccount(Environment.UserName).Translate(typeof(System.Security.Principal.SecurityIdentifier)).Value);
            }
            catch
            {
                mlInfos["DictionaryFile"] = "Readout failed.";
            }

            //get the extensions
            Dictionary<string, string> extInfos = new Dictionary<string, string>();
            try
            {
                if (Dictionary != null && Dictionary.DictionaryDAL.Extensions.Count > 0)
                    foreach (IExtension extension in Dictionary.DictionaryDAL.Extensions)
                        extInfos["Extension"] = extension.ToString() + " - (" + extension.Id + ")";
                else
                    extInfos["Extensions"] = "No extensions.";
            }
            catch
            {
                extInfos["Extensions"] = "Readout failed.";
            }

            //fetch some basic system information
            Dictionary<string, string> sysInfos = new Dictionary<string, string>();
            try
            {
                sysInfos["OSVersion"] = System.Environment.OSVersion.ToString();
                sysInfos["IEVersion"] = MLifter.Generics.Methods.GetInternetExplorerVersion().ToString();
                sysInfos["CLRVersion"] = System.Environment.Version.ToString();
                sysInfos["SystemDirectory"] = System.Environment.SystemDirectory;
                sysInfos["WMPVersion"] = MLifter.Generics.Methods.GetWindowsMediaPlayerVersion().ToString();
            }
            catch
            {
                sysInfos["SystemInformation"] = "Readout failed.";
            }
            #endregion

            #region write data
            //add the XSL to the output
            FileInfo errorReportStylesheet = new FileInfo(Path.Combine(Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), Path.Combine(Properties.Settings.Default.AppDataFolder, Properties.Settings.Default.AppDataFolderDesigns)), @"System\ErrorHandler\default.xsl"));
            if (errorReportStylesheet.Exists)
            {
                ZipEntry styleEntry = new ZipEntry("ErrorReport.xsl");
                stream.PutNextEntry(styleEntry);
                using (FileStream styleStream = errorReportStylesheet.OpenRead())
                {
                    try
                    {
                        int i;
                        do
                        {
                            i = styleStream.ReadByte();
                            if (i != -1) stream.WriteByte((byte)i);
                        } while (i != -1);
                    }
                    catch (IOException) { }
                }
            }

            //write the error report
            ZipEntry entry = new ZipEntry("ErrorReport.xml");
            stream.PutNextEntry(entry);

            XmlWriterSettings settings = new XmlWriterSettings() { CloseOutput = true, Encoding = Encoding.Unicode, Indent = true };
            XmlWriter errorReportXML = XmlWriter.Create(stream, settings);
            errorReportXML.WriteStartDocument();
            if (errorReportStylesheet.Exists)
            {
                errorReportXML.WriteProcessingInstruction("xml-stylesheet", string.Format("type='Text/xsl' href='{0}'", errorReportStylesheet.FullName));
                errorReportXML.WriteProcessingInstruction("xml-stylesheet", string.Format("type='Text/xsl' href='{0}'", "ErrorReport.xsl"));
            }

            errorReportXML.WriteComment(String.Format("{0} {1} Error Report, generated {2}", AssemblyData.Title, AssemblyData.AssemblyVersion, System.DateTime.Now.ToString()));
            errorReportXML.WriteStartElement("ErrorReport");

            errorReportXML.WriteStartElement("MLInformation");
            foreach (KeyValuePair<string, string> pair in mlInfos)
                errorReportXML.WriteElementString(pair.Key, pair.Value);
            errorReportXML.WriteEndElement();

            errorReportXML.WriteStartElement("ExtensionsInformation");
            foreach (KeyValuePair<string, string> pair in extInfos)
                errorReportXML.WriteElementString(pair.Key, pair.Value);
            errorReportXML.WriteEndElement();

            errorReportXML.WriteStartElement("SystemInformation");
            foreach (KeyValuePair<string, string> pair in sysInfos)
                errorReportXML.WriteElementString(pair.Key, pair.Value);
            errorReportXML.WriteEndElement();

            XMLWriteException(errorReportXML, exception);

            errorReportXML.WriteEndElement();
            errorReportXML.Flush();
            #endregion
        }