-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Code Quality: Remove ini-parser-netstandard dependency #15654
Open
0x5bfa
wants to merge
18
commits into
files-community:main
Choose a base branch
from
0x5bfa:5bfa/CQ-WindowsINIService
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−56
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5b24ddf
Init
0x5bfa e1e060d
Update
0x5bfa 0ddfeb3
Address #15732
0x5bfa fdb32be
Update IniSectionDataItem.cs
0x5bfa 5079795
Update src/Files.App/Services/Windows/WindowsIniService.cs
0x5bfa 820d8c4
Req
0x5bfa a409a6b
Update src/Files.App/Services/Windows/WindowsIniService.cs
0x5bfa 3db786f
Update src/Files.App/ViewModels/ShellViewModel.cs
0x5bfa 14d9d27
Merge branch '5bfa/CQ-WindowsINIService' of https://github.com/0x5bfa…
0x5bfa 1ea3f4a
Merge branch 'main' into 5bfa/CQ-WindowsINIService
yaira2 d899fcb
Remove `path` arg from all callers and merge into single method
0x5bfa e03a530
Merge branch '5bfa/CQ-WindowsINIService' of https://github.com/0x5bfa…
0x5bfa dc22c02
Revert "Remove `path` arg from all callers and merge into single method"
0x5bfa 2c7b9c0
Update
0x5bfa e7425e2
Merge branch 'main' into 5bfa/CQ-WindowsINIService
yaira2 a8bf3a4
Update src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
yaira2 60b7675
Update ShellViewModel.cs
yaira2 ea11d25
Update src/Files.App/ViewModels/ShellViewModel.cs
yaira2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Data.Contracts | ||
{ | ||
/// <summary> | ||
/// Provides service to retrieve value from an INI file. | ||
/// </summary> | ||
public interface IWindowsIniService | ||
{ | ||
/// <summary> | ||
/// Gets parsed data of INI file of a folder with each section. | ||
/// </summary> | ||
/// <remarks> | ||
/// While there's Win32API GetPrivateProfileString, this API can only used for single key. | ||
/// <br/> | ||
/// For more information about INI format, visit <a href="https://en.wikipedia.org/wiki/INI_file"/>. | ||
/// </remarks> | ||
/// <param name="filePath">The INI file to look up.</param> | ||
/// <param name="dataItem">The data class to hold the INI data.</param> | ||
/// <returns>Returns true if succeeded; otherwise, false.</returns> | ||
List<IniSectionDataItem> GetData(string filePath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Files.App.Data.Items | ||
{ | ||
/// <summary> | ||
/// Represents item of ini file's section. | ||
/// </summary> | ||
public class IniSectionDataItem | ||
{ | ||
public string SectionName { get; set; } = ""; | ||
|
||
public IDictionary<string, string> Parameters { get; set; } = ImmutableDictionary<string, string>.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Services | ||
{ | ||
/// <inheritdoc cref="IWindowsIniService"/> | ||
public sealed class WindowsIniService : IWindowsIniService | ||
{ | ||
/// <inheritdoc/> | ||
public List<IniSectionDataItem> GetData(string filePath) | ||
{ | ||
var iniPath = SystemIO.Path.Combine(filePath); | ||
if (!SystemIO.File.Exists(iniPath)) | ||
return []; | ||
|
||
var lines = Enumerable.Empty<string>().ToList(); | ||
|
||
try | ||
{ | ||
lines = SystemIO.File.ReadLines(iniPath) | ||
.Where(line => !line.StartsWith(';') && !string.IsNullOrEmpty(line)) | ||
.ToList(); | ||
} | ||
catch (UnauthorizedAccessException) | ||
{ | ||
return []; | ||
} | ||
|
||
// Get sections | ||
var sections = lines | ||
.Where(line => line.StartsWith('[') && line.EndsWith(']')); | ||
|
||
// Get section line indexes | ||
List<int> sectionLineIndexes = []; | ||
foreach (var section in sections) | ||
sectionLineIndexes.Add(lines.IndexOf(section)); | ||
|
||
List<IniSectionDataItem> dataItems = []; | ||
|
||
for (int index = 0; index < sectionLineIndexes.Count; index++) | ||
{ | ||
var sectionIndex = sectionLineIndexes[index]; | ||
|
||
var count = | ||
index + 1 == sectionLineIndexes.Count | ||
? (lines.Count - 1) - sectionIndex | ||
: sectionLineIndexes[index + 1] - sectionIndex; | ||
|
||
if (count == 0) | ||
continue; | ||
|
||
var range = lines.GetRange(sectionIndex + 1, count); | ||
|
||
var sectionName = lines[sectionLineIndexes[index]].TrimStart('[').TrimEnd(']'); | ||
|
||
// Read data | ||
var parameters = range | ||
// Split the lines into key and value | ||
.Select(line => line.Split('=')) | ||
// Validate | ||
.Where(parts => parts.Length == 2) | ||
// Gather as dictionary | ||
.ToDictionary(parts => parts[0].Trim(), parts => parts[1].Trim()); | ||
|
||
dataItems.Add(new() | ||
{ | ||
SectionName = sectionName, | ||
Parameters = parameters, | ||
}); | ||
} | ||
|
||
return dataItems; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change is appropriate, because this method is to get information for a given path, not for the current context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this
string path
is alwaysWorkindDirectory
.I removed this argument from all callers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we should use the
path
parameter here, because I don't think static helper methods should be context dependent.Even if we make this context dependent,
ShellPage
should be null-safe.