/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/Workspaces/WorkspacesCsharpLibrary/Utils/IOUtils.cs
47 строк
1 KB
Kai Tao
Cmdpal extension: Powertoys extension for cmdpal (#44006)
23 дек 2025, 16:07
Не верифицирован
23 дек 2025, 16:07
d87dde1
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.IO; using System.IO.Abstractions; using System.Threading.Tasks; namespace WorkspacesCsharpLibrary.Utils; public class IOUtils { private readonly IFileSystem _fileSystem = new FileSystem(); public void WriteFile(string fileName, string data) { _fileSystem.File.WriteAllText(fileName, data); } public string ReadFile(string fileName) { if (_fileSystem.File.Exists(fileName)) { int attempts = 0; while (attempts < 10) { try { using FileSystemStream inputStream = _fileSystem.File.Open(fileName, FileMode.Open); using StreamReader reader = new(inputStream); string data = reader.ReadToEnd(); inputStream.Close(); return data; } catch (Exception) { Task.Delay(10).Wait(); } attempts++; } } return string.Empty; } }