gpt4 book ai didi

zip - Monotouch - ICSharpCode.SharpZipLib 出现错误

转载 作者:行者123 更新时间:2023-12-02 03:43:52 25 4
gpt4 key购买 nike

大家好,

我正在尝试使用 ICSharpCode.SharpZipLib 库生成 Zip 文件,但它抛出了一个非常奇怪的错误。

代码:

public static void ZipFiles(string inputFolderPath, string outputPathAndFile, string password)       
{
ArrayList ar = GenerateFileList(inputFolderPath); // generate file list
int TrimLength = (Directory.GetParent(inputFolderPath)).ToString().Length;

TrimLength += 1; //remove '\'
FileStream ostream;
byte[] obuffer;

ZipOutputStream oZipStream = new ZipOutputStream(File.Create(outputPathAndFile)); // create zip stream
if (password != null && password != String.Empty)
oZipStream.Password = password;
oZipStream.SetLevel(9); // maximum compression
ZipEntry oZipEntry;
foreach (string Fil in ar) // for each file, generate a zipentry
{
oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength));
oZipStream.PutNextEntry(oZipEntry);

if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory
{
ostream = File.OpenRead(Fil);
obuffer = new byte[ostream.Length];
ostream.Read(obuffer, 0, obuffer.Length);
oZipStream.Write(obuffer, 0, obuffer.Length);
}
}
oZipStream.Finish();
oZipStream.Close();
}


private static ArrayList GenerateFileList(string Dir)
{
ArrayList fils = new ArrayList();
bool Empty = true;
foreach (string file in Directory.GetFiles(Dir,"*.xml")) // add each file in directory
{
fils.Add(file);
Empty = false;
}

if (Empty)
{
if (Directory.GetDirectories(Dir).Length == 0)
// if directory is completely empty, add it
{
fils.Add(Dir + @"/");
}
}

foreach (string dirs in Directory.GetDirectories(Dir)) // recursive
{
foreach (object obj in GenerateFileList(dirs))
{
fils.Add(obj);
}
}
return fils; // return file list
}

错误:

Unhandled Exception: System.NotSupportedException: CodePage 437 not supported
at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0
at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (System.String str) [0x00000] in <filename unknown>:0
at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToArray (Int32 flags, System.String str) [0x00000] in <filename unknown>:0
at ICSharpCode.SharpZipLib.Zip.ZipOutputStream.PutNextEntry (ICSharpCode.SharpZipLib.Zip.ZipEntry entry) [0x00000] in <filename unknown>:0
at WpfPrototype1.MainInvoicesView.ZipFiles (System.String inputFolderPath, System.String outputPathAndFile, System.String password) [0x00000] in <filename unknown>:0
at WpfPrototype1.MainInvoicesView.<ViewDidLoad>m__6 (System.Object , System.EventArgs ) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in <filename unknown>:0
at WpfPrototype1.Application.Main (System.String[] args) [0x00000] in <filename unknown>:0

如何使此代码支持 CodePage 437?

问候,
克劳迪奥

最佳答案

MonoTouch 删除了它无法静态确定您需要的 I18N 代码页。在这种情况下,您可以通过以下两种方法之一强制单点触控保留所需的代码页集合(West):

  1. 点击“项目”->“[项目名称] 选项”
  2. 选择 iPhone 版本
  3. 此时您有两个选择A。从 I18n 程序集列表中选择“west”b.将“-i18n=west”添加到“额外参数”

注意:您需要对配置和平台的每种组合执行步骤 #3。

关于zip - Monotouch - ICSharpCode.SharpZipLib 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4600923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com