我正在尝试将SharpZip.unzipper用于我的Windows Phone 8.1。但是它没有阅读一些代码。由于我对Windows Phone开发还不熟悉,请告诉我WP8.1以下代码的替代方法
using System.Windows.Resources;
public Stream GetFileStream(string filename)
{
if (fileEntries == null)
fileEntries = ParseCentralDirectory(); //We need to do this in case the zip is in a format Silverligth doesn't like
long position = this.stream.Position;
this.stream.Seek(0, SeekOrigin.Begin);
Uri fileUri = new Uri(filename, UriKind.Relative);
StreamResourceInfo info = new StreamResourceInfo(this.stream, null);
StreamResourceInfo stream = System.Windows.Application.GetResourceStream(info, fileUri);
this.stream.Position = position;
if (stream != null)
return stream.Stream;
return null;
}
Windows.Resources
似乎不见了
我无法致电StreamResourceInfo, System.Windows.Application
我尝试过使用App
。但GetResourceSteam
我不知道该怎么做
答案 0 :(得分:0)
WP8.1运行时与WP8.1 Silverlight之间存在很多差异。
您拥有的代码示例将在WP8.0 SL和WP8.1 SL上运行。
看起来您创建了一个Windows Phone 8.1运行时项目。没有System.Windows.Application.GetResourceStream()
将其转换为兼容的8.1运行时流,或者重新创建项目以改为以Silverlight为目标。
// sample
private async void ZipLibraryTest()
{
// create the full path
string zip = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "filename.zip");
// create the storage file with the file name
StorageFile sf = await StorageFile.GetFileFromPathAsync(zip);
// create the IO Stream
using (System.IO.Stream output = await sf.OpenStreamForWriteAsync())
{
// open the zip file for writing, use the stream from the file
ZipFile zf = ZipFile.Create(output);
// rest of your code
// ...
// ...
// close the zip file
zf.Close();
}
}