-
-
Notifications
You must be signed in to change notification settings - Fork 462
fix: Unable to obtain Windows server information #963
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
Open
lxdklp
wants to merge
5
commits into
lollipopkit:main
Choose a base branch
from
lxdklp:main
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.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
22aa718
fix: FormatException: Unexpected extension byte (at offset 8) error
lxdklp 6f0874e
fix: PowerShell script error repair, Windows data parsing repair
lxdklp 4c6d764
fix: Unable to obtain network card information
lxdklp c7ea1c8
fix: Unable to obtain system startup time
lxdklp 13bfd3d
fix conversation as resolved.
lxdklp 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 hidden or 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 hidden or 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,66 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:fl_lib/fl_lib.dart'; | ||
| import 'package:flutter_gbk2utf8/flutter_gbk2utf8.dart'; | ||
|
|
||
| /// Utility class for decoding SSH command output with encoding fallback | ||
| class SSHDecoder { | ||
| /// Decodes bytes to string with multiple encoding fallback strategies | ||
| /// | ||
| /// Tries in order: | ||
| /// 1. UTF-8 (with allowMalformed for lenient parsing) | ||
| /// - Windows PowerShell scripts now set UTF-8 output encoding by default | ||
| /// 2. GBK (for Windows Chinese systems) | ||
| /// - In some cases, Windows will still revert to GBK. | ||
| /// - Only attempted if UTF-8 produces replacement characters (�) | ||
| static String decode( | ||
| List<int> bytes, { | ||
| bool isWindows = false, | ||
| String? context, | ||
| }) { | ||
| if (bytes.isEmpty) return ''; | ||
|
|
||
| // Try UTF-8 first with allowMalformed | ||
| try { | ||
| final result = utf8.decode(bytes, allowMalformed: true); | ||
| // Check if there are replacement characters indicating decode failure | ||
| // For non-Windows systems, always use UTF-8 result | ||
| if (!result.contains('�') || !isWindows) { | ||
| return result; | ||
| } | ||
| // For Windows with replacement chars, log and try GBK fallback | ||
| if (isWindows && result.contains('�')) { | ||
| final contextInfo = context != null ? ' [$context]' : ''; | ||
| Loggers.app.info('UTF-8 decode has replacement chars$contextInfo, trying GBK fallback'); | ||
| } | ||
| } catch (e) { | ||
| final contextInfo = context != null ? ' [$context]' : ''; | ||
| Loggers.app.warning('UTF-8 decode failed$contextInfo: $e'); | ||
| } | ||
|
|
||
| // For Windows or when UTF-8 has replacement chars, try GBK | ||
| try { | ||
| return gbk.decode(bytes); | ||
| } catch (e) { | ||
| final contextInfo = context != null ? ' [$context]' : ''; | ||
| Loggers.app.warning('GBK decode failed$contextInfo: $e'); | ||
| // Return empty string if all decoding attempts fail | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| /// Encodes string to bytes for SSH command input | ||
| /// | ||
| /// Uses GBK for Windows, UTF-8 for others | ||
| static List<int> encode(String text, {bool isWindows = false}) { | ||
| if (isWindows) { | ||
| try { | ||
| return gbk.encode(text); | ||
| } catch (e) { | ||
| Loggers.app.warning('GBK encode failed: $e, falling back to UTF-8'); | ||
| return utf8.encode(text); | ||
| } | ||
| } | ||
| return utf8.encode(text); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.