本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.FindEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.FindEntry方法的具体用法?C# ZipFile.FindEntry怎么用?C# ZipFile.FindEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.FindEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadShareString
public static void LoadShareString(string file)
{
if (ShareString.file == file)
return;
ZipFile myZip = new ZipFile(file);
int index = myZip.FindEntry("xl/sharedStrings.xml", true);
Stream ss = myZip.GetInputStream(index);
XmlReader myReader = XmlReader.Create(ss);
string content = string.Empty;
bool inEntry = false;
bool inContent = false;
int postion = 0;
while (myReader.Read())
{
switch (myReader.NodeType)
{
case XmlNodeType.Element:
if (myReader.Name == "sst")
{
int count = Convert.ToInt32(myReader.GetAttribute("uniqueCount"));
shareWords = new string[count];
}
else if (myReader.Name == "si")
{
inEntry = true;
}
else if (myReader.Name == "t" && inEntry)
{
inContent = true;
}
break;
case XmlNodeType.Text:
if (inContent)
{
content += myReader.Value;
}
break;
case XmlNodeType.EndElement:
if (myReader.Name == "si")
{
inEntry = false;
shareWords[postion++] = content;
content = string.Empty;
}
else if (myReader.Name == "t")
{
inContent = false;
}
break;
}
}
myReader.Close();
ss.Dispose();
}
示例2: GetSheetData
/// <summary>
/// 获取sheet表单内容。
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public SheetData GetSheetData(int index)
{
if (ShareString.shareWords == null)
{
ShareString.LoadShareString(filePath);
}
ZipFile myZip = new ZipFile(filePath);
int num = myZip.FindEntry(mySheetList[index].path, true);
Stream ss = myZip.GetInputStream(num);
SheetData mySheetData = new SheetData(ss);
return mySheetData;
}
示例3: AssertDoesNotContainFile
private void AssertDoesNotContainFile(string partialPath)
{
ZipFile f = null;
try
{
f = new ZipFile(_destinationZip);
Assert.AreEqual(-1, f.FindEntry(GetZipFileInternalPath(partialPath), true));
}
finally
{
if (f != null)
{
f.Close();
}
}
}
示例4: GetContentRaw
public byte[] GetContentRaw(string loc)
{
byte[] cont = null;
ZipFile zipFile = new ZipFile(FileLoc);
int i = zipFile.FindEntry(loc, false);
if (i >= 0)
{
ZipEntry ze = zipFile[i];
Stream s = zipFile.GetInputStream(ze);
byte[] buff = new byte[(int)ze.Size];
s.Read(buff, 0, buff.Length);
cont = buff;
}
zipFile.Close();
return cont;
}
示例5: GetContentRaw
public byte[] GetContentRaw(string loc)
{
byte[] cont = null;
ZipFile zipFile = new ZipFile(this.zipArchive);
int i = zipFile.FindEntry(loc, false);
if (i >= 0)
{
ZipEntry ze = zipFile[i];
Stream s = zipFile.GetInputStream(ze);
byte[] buff = new byte[(int)ze.Size];
s.Read(buff, 0, buff.Length);
cont = buff;
}
zipFile.IsStreamOwner = false; zipFile.Close();
this.zipArchive.Position = 0;
return cont;
}
示例6: ReadDDSFile
public Bitmap ReadDDSFile(string pakFile, string internalFile)
{
string key = pakFile + "!" + internalFile;
Debug.Assert(internalFile.EndsWith("dds"));
if (!imageCache.ContainsKey(key)) {
var itempak = OpenPAKFile(Path.Combine(aionPath, pakFile));
using (ZipFile zFile = new ZipFile(itempak)) {
int entrynum = zFile.FindEntry(internalFile, true);
if (entrynum == -1) { return null; }
var entry = zFile[entrynum];
var iconFile = zFile.GetInputStream(entry);
byte[] bytes = new byte[entry.Size];
iconFile.Read(bytes, 0, bytes.Length);
Bitmap b = JitConverter.DDSDataToBMP(bytes);
imageCache[key] = b;
}
}
return imageCache[key];
}
示例7: InstallAssemblyPackage
/// <summary>
/// Copies assembly files from package to Bin folder
/// </summary>
public static void InstallAssemblyPackage(List<UpdateFileInfo> updateFiles, ZipFile zipPackage)
{
// Bin path!
string extenderPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Bin");
foreach (UpdateFileInfo fileInfo in updateFiles)
{
if (IsPackageFileForbidden(fileInfo.FilePath))
continue;
// the file path
string installPath = Path.Combine(extenderPath, fileInfo.FilePath);
// Ignore existence
if (fileInfo.IgnoreExistence && File.Exists(installPath))
continue;
// find file in zip package
int index = zipPackage.FindEntry(fileInfo.FilePath, true);
if (index == -1)
throw new InvalidDataException("Package files are invalid");
// Ignore specifed version
int compare = 1;
if (!string.IsNullOrEmpty(fileInfo.IgnoreASProxyVersion))
compare = Common.CompareASProxyVersions(Consts.General.ASProxyVersion, fileInfo.IgnoreASProxyVersion);
// Only check if they are not equal
if (compare != 0)
{
// Installable, do it!
using (Stream zipStream = zipPackage.GetInputStream(index))
using (FileStream file = new FileStream(installPath, FileMode.Create, FileAccess.Write, FileShare.None))
{
ReadWriteStream(zipStream, file);
}
}
}
}
示例8: ReadModInfo
private string ReadModInfo()
{
using (var stream = this.File.OpenRead())
{
using (var zip = new ZipFile(stream))
{
int index = zip.FindEntry(Constants.MCModInfoFile, true);
if (index == -1)
{
Diagnostic.Error("Could not find {0} in {1}", Constants.MCModInfoFile, this.File);
return null;
}
using (var entryStream = zip.GetInputStream(index))
{
using (var reader = new StreamReader(entryStream))
{
return reader.ReadToEnd();
}
}
}
}
}
示例9: Crypto_AddEncryptedEntryToExistingArchiveSafe
public void Crypto_AddEncryptedEntryToExistingArchiveSafe()
{
MemoryStream ms = new MemoryStream();
byte[] rawData;
using (ZipFile testFile = new ZipFile(ms))
{
testFile.IsStreamOwner = false;
testFile.BeginUpdate();
testFile.Add(new StringMemoryDataSource("Aha"), "No1", CompressionMethod.Stored);
testFile.Add(new StringMemoryDataSource("And so it goes"), "No2", CompressionMethod.Stored);
testFile.Add(new StringMemoryDataSource("No3"), "No3", CompressionMethod.Stored);
testFile.CommitUpdate();
Assert.IsTrue(testFile.TestArchive(true));
rawData = ms.ToArray();
}
ms = new MemoryStream(rawData);
using (ZipFile testFile = new ZipFile(ms))
{
Assert.IsTrue(testFile.TestArchive(true));
testFile.BeginUpdate(new MemoryArchiveStorage(FileUpdateMode.Safe));
testFile.Password = "pwd";
testFile.Add(new StringMemoryDataSource("Zapata!"), "encrypttest.xml");
testFile.CommitUpdate();
Assert.IsTrue(testFile.TestArchive(true));
int entryIndex = testFile.FindEntry("encrypttest.xml", true);
Assert.IsNotNull(entryIndex >= 0);
Assert.IsTrue(testFile[entryIndex].IsCrypted);
}
}
示例10: FindEntry
public void FindEntry()
{
string tempFile = GetTempFilePath();
Assert.IsNotNull(tempFile, "No permission to execute this test?");
tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");
MakeZipFile(tempFile, new string[] { "Farriera", "Champagne", "Urban myth" }, 10, "Aha");
using (ZipFile zipFile = new ZipFile(tempFile)) {
Assert.AreEqual(3, zipFile.Count, "Expected 1 entry");
int testIndex = zipFile.FindEntry("Farriera", false);
Assert.AreEqual(0, testIndex, "Case sensitive find failure");
Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", false) == 0);
testIndex = zipFile.FindEntry("Farriera", true);
Assert.AreEqual(0, testIndex, "Case insensitive find failure");
Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "Farriera", true) == 0);
testIndex = zipFile.FindEntry("urban mYTH", false);
Assert.AreEqual(-1, testIndex, "Case sensitive find failure");
testIndex = zipFile.FindEntry("urban mYTH", true);
Assert.AreEqual(2, testIndex, "Case insensitive find failure");
Assert.IsTrue(string.Compare(zipFile[testIndex].Name, "urban mYTH", true) == 0);
testIndex = zipFile.FindEntry("Champane.", false);
Assert.AreEqual(-1, testIndex, "Case sensitive find failure");
testIndex = zipFile.FindEntry("Champane.", true);
Assert.AreEqual(-1, testIndex, "Case insensitive find failure");
zipFile.Close();
}
File.Delete(tempFile);
}
示例11: formSettings_Load
private void formSettings_Load(object sender, EventArgs e)
{
// Set installation path textbox
textInstallPath.Text = Properties.Settings.Default.InstallPath;
checkConflicts.Checked = SettingsManager.DisableConflictCheck;
checkEnableSound.Checked = Properties.Settings.Default.EnableSound;
listThemes.SelectedIndex = 0;
if(Directory.Exists("Themes"))
{
foreach(string file in Directory.GetFiles("Themes", "*.sbtheme"))
{
// Read theme names
ZipFile themeZip = new ZipFile(file);
var themeEntry = themeZip.FindEntry("Theme.xml", true);
if(themeEntry >= 0)
{
var themeStream = themeZip.GetInputStream(themeZip[themeEntry]);
using (StreamReader themeReader = new StreamReader(themeStream))
{
XmlSerializer themeSerializer = new XmlSerializer(typeof(ThemeXml.Theme));
var theme = (ThemeXml.Theme)themeSerializer.Deserialize(themeReader);
listThemes.Items.Add(theme.Name);
themeFiles.Add(file);
if (Properties.Settings.Default.ThemeFile == file) listThemes.SelectedIndex = themeFiles.Count-1;
}
}
}
} else
{
tabControl.TabPages.RemoveAt(1);
}
}
示例12: InstallDictionary
private void InstallDictionary(ZipFile zipFile)
{
string installed = null;
foreach (ZipEntry entry in zipFile)
{
if (entry.Name.EndsWith(".dic"))
{
string path;
string code;
int pos = entry.Name.LastIndexOf('/');
if (pos == -1)
{
path = null;
code = entry.Name;
}
else
{
path = entry.Name.Substring(0, pos + 1);
code = entry.Name.Substring(pos + 1);
}
code = code.Substring(0, code.Length - 4);
try
{
CultureInfo.GetCultureInfo(code);
}
catch (CultureNotFoundException)
{
continue;
}
int affEntryIndex = zipFile.FindEntry(
path + code + ".aff",
true
);
if (affEntryIndex == -1)
{
continue;
}
using (var source = zipFile.GetInputStream(entry))
{
SaveFile(source, code + ".dic");
}
using (var source = zipFile.GetInputStream(affEntryIndex))
{
SaveFile(source, code + ".aff");
}
// Install the first found, if there are multiple present.
if (installed == null)
installed = code;
}
}
if (installed != null)
{
using (var key = Program.BaseKey)
{
key.SetValue("Spell Check Language", installed);
}
LoadDictionary();
}
return;
}
示例13: GetApkIcon
/// <summary>
/// Получение иконки APK-приложения
/// </summary>
/// <param name="filename">Путь до приложения</param>
/// <returns>Икорка</returns>
public static ImageSource GetApkIcon(string filename)
{
//Нужно создавать новые экземпляры, ибо BeginOutputReadLine() блухает
Environment.aaptProc.StartInfo.Arguments = "dump badging \"" + filename + "\"";
ProcessStartInfo pStartInfo = Environment.aaptProc.StartInfo;
Environment.aaptProc = new Process();
Environment.aaptProc.StartInfo = pStartInfo;
StringBuilder output = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
{
Environment.aaptProc.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
outputWaitHandle.Set();
else
output.AppendLine(e.Data);
};
Environment.aaptProc.Start();
Environment.aaptProc.BeginOutputReadLine();
if (Environment.aaptProc.WaitForExit(1000) && outputWaitHandle.WaitOne(1000))
{
Regex regex = new Regex(@"^application:\slabel='(.*)'\sicon='(.*)'$");
string IconPath = string.Empty;
foreach (string line in output.ToString().Split(new string[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
if (regex.IsMatch(line))
IconPath = regex.Match(line).Groups[2].Value;
}
if (!string.IsNullOrEmpty(IconPath))
{
ZipFile zip = new ZipFile(filename);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = zip.GetInputStream(zip.FindEntry(IconPath, true));
bitmap.EndInit();
bitmap.Freeze();
zip.Close();
return bitmap;
}
}
}
return null;
}
示例14: AssertHasReasonableContents
private void AssertHasReasonableContents()
{
Assert.IsTrue(File.Exists(_destinationZip));
ZipFile f = null;
try
{
f = new ZipFile(_destinationZip);
Assert.AreNotEqual(-1, f.FindEntry("PRETEND/PRETEND.lift", true));
}
finally
{
if (f != null)
{
f.Close();
}
}
}
示例15: ExtractFromOpenDocumentFormat
/// <summary>
/// Extracts all the embedded object from the OpenDocument <paramref name="inputFile"/> to the
/// <see cref="outputFolder"/> and returns the files with full path as a list of strings
/// </summary>
/// <param name="inputFile">The OpenDocument format file</param>
/// <param name="outputFolder">The output folder</param>
/// <returns>List with files or en empty list when there are nog embedded files</returns>
/// <exception cref="OEFileIsPasswordProtected">Raised when the OpenDocument format file is password protected</exception>
internal List<string> ExtractFromOpenDocumentFormat(string inputFile, string outputFolder)
{
var result = new List<string>();
var zipFile = new ZipFile(inputFile);
// Check if the file is password protected
var manifestEntry = zipFile.FindEntry("META-INF/manifest.xml", true);
if (manifestEntry != -1)
{
using (var manifestEntryStream = zipFile.GetInputStream(manifestEntry))
using (var manifestEntryMemoryStream = new MemoryStream())
{
manifestEntryStream.CopyTo(manifestEntryMemoryStream);
manifestEntryMemoryStream.Position = 0;
using (var streamReader = new StreamReader(manifestEntryMemoryStream))
{
var manifest = streamReader.ReadToEnd();
if (manifest.ToUpperInvariant().Contains("ENCRYPTION-DATA"))
throw new OEFileIsPasswordProtected("The file '" + Path.GetFileName(inputFile) +
"' is password protected");
}
}
}
foreach (ZipEntry zipEntry in zipFile)
{
if (!zipEntry.IsFile) continue;
if (zipEntry.IsCrypted)
throw new OEFileIsPasswordProtected("The file '" + Path.GetFileName(inputFile) +
"' is password protected");
var name = zipEntry.Name.ToUpperInvariant();
if (!name.StartsWith("OBJECT") || name.Contains("/"))
continue;
string fileName = null;
var objectReplacementFileIndex = zipFile.FindEntry("ObjectReplacements/" + name, true);
if (objectReplacementFileIndex != -1)
fileName = Extraction.GetFileNameFromObjectReplacementFile(zipFile, objectReplacementFileIndex);
using (var zipEntryStream = zipFile.GetInputStream(zipEntry))
using (var zipEntryMemoryStream = new MemoryStream())
{
zipEntryStream.CopyTo(zipEntryMemoryStream);
using (var compoundFile = new CompoundFile(zipEntryMemoryStream))
result.Add(Extraction.SaveFromStorageNode(compoundFile.RootStorage, outputFolder, fileName));
}
}
return result;
}