Skip to content

Fix: Fixed issue where preview of ANSI text didn't work #10083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Files.App/Filesystem/BaseStorage/BaseStorageFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -22,7 +23,7 @@ public abstract class BaseStorageFile : IBaseStorageFile
public StorageProvider Provider => null;

public abstract DateTimeOffset DateCreated { get; }
public abstract FileAttributes Attributes { get; }
public abstract Windows.Storage.FileAttributes Attributes { get; }
public abstract string FolderRelativeId { get; }

public abstract IStorageItemExtraProperties Properties { get; }
Expand Down Expand Up @@ -96,15 +97,17 @@ public static IAsyncOperation<BaseStorageFile> GetFileFromPathAsync(string path)
public async Task<string> ReadTextAsync(int maxLength = -1)
{
using var inputStream = await OpenReadAsync();
using var dataReader = new DataReader(inputStream);
using var stream = inputStream.AsStreamForRead();
using var dataReader = new StreamReader(stream, true);
StringBuilder builder = new();
uint bytesRead, bytesToRead;
int charsRead, charsToRead;
do
{
bytesToRead = maxLength < 0 ? 4096 : (uint)Math.Min(maxLength, 4096);
bytesRead = await dataReader.LoadAsync(bytesToRead);
builder.Append(dataReader.ReadString(bytesRead));
} while (bytesRead > 0 && inputStream.Position < inputStream.Size);
charsToRead = maxLength < 0 ? 4096 : Math.Min(maxLength, 4096);
var data = new char[charsToRead];
charsRead = await dataReader.ReadAsync(data);
builder.Append(data);
} while (charsRead > 0 && inputStream.Position < inputStream.Size);
return builder.ToString();
}

Expand Down