Skip to content

Commit ba374c0

Browse files
committed
chore(package_info_plus): Update dependencies and do necessary changes
1 parent 199c5bf commit ba374c0

8 files changed

Lines changed: 110 additions & 102 deletions

File tree

packages/package_info_plus/package_info_plus/lib/src/file_attribute.dart

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,38 @@ class FileAttributes {
2828
late final DateTime? lastWriteTime;
2929

3030
FileAttributes(this.filePath) {
31-
final (:creationTime, :lastWriteTime) =
32-
getFileCreationAndLastWriteTime(filePath);
31+
final (:creationTime, :lastWriteTime) = getFileCreationAndLastWriteTime(
32+
filePath,
33+
);
3334

3435
this.creationTime = creationTime;
3536
this.lastWriteTime = lastWriteTime;
3637
}
3738

38-
static ({
39-
DateTime? creationTime,
40-
DateTime? lastWriteTime,
41-
}) getFileCreationAndLastWriteTime(String filePath) {
39+
static ({DateTime? creationTime, DateTime? lastWriteTime})
40+
getFileCreationAndLastWriteTime(String filePath) {
4241
if (!File(filePath).existsSync()) {
4342
throw ArgumentError.value(filePath, 'filePath', 'File not present');
4443
}
4544

46-
final lptstrFilename = TEXT(filePath);
45+
final lptstrFilename = filePath.toPcwstr();
4746
final lpFileInformation = calloc<FILEATTRIBUTEDATA>();
4847

4948
try {
50-
if (GetFileAttributesEx(lptstrFilename, 0, lpFileInformation) == 0) {
51-
throw WindowsException(HRESULT_FROM_WIN32(GetLastError()));
49+
final result = GetFileAttributesEx(
50+
lptstrFilename,
51+
GetFileExInfoStandard,
52+
lpFileInformation,
53+
);
54+
if (!result.value) {
55+
throw WindowsException(result.error.toHRESULT());
5256
}
5357

5458
final FILEATTRIBUTEDATA fileInformation = lpFileInformation.ref;
5559

5660
return (
57-
creationTime: fileTimeToDartDateTime(
58-
fileInformation.ftCreationTime,
59-
),
60-
lastWriteTime: fileTimeToDartDateTime(
61-
fileInformation.ftLastWriteTime,
62-
),
61+
creationTime: fileTimeToDartDateTime(fileInformation.ftCreationTime),
62+
lastWriteTime: fileTimeToDartDateTime(fileInformation.ftLastWriteTime),
6363
);
6464
} finally {
6565
free(lptstrFilename);

packages/package_info_plus/package_info_plus/lib/src/file_version_info.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ class FileVersionInfo {
6565
for (final langCodepage in langCodepages) {
6666
final lang = toHex4(langCodepage[0]);
6767
final codepage = toHex4(langCodepage[1]);
68-
final lpSubBlock = TEXT('\\StringFileInfo\\$lang$codepage\\$name');
69-
final res =
70-
VerQueryValue(_data.lpBlock, lpSubBlock, lplpBuffer.cast(), puLen);
68+
final lpSubBlock = '\\StringFileInfo\\$lang$codepage\\$name'.toPcwstr();
69+
final res = VerQueryValue(
70+
_data.lpBlock,
71+
lpSubBlock,
72+
lplpBuffer.cast(),
73+
puLen,
74+
);
7175
free(lpSubBlock);
7276

73-
if (res != 0 && lplpBuffer.address != 0 && puLen.value > 0) {
77+
if (res && lplpBuffer.address != 0 && puLen.value > 0) {
7478
return lplpBuffer.value.toDartString();
7579
}
7680
}
@@ -87,20 +91,22 @@ class FileVersionInfo {
8791
throw ArgumentError.value(filePath, 'filePath', 'File not present');
8892
}
8993

90-
final lptstrFilename = TEXT(filePath);
91-
final dwLen = GetFileVersionInfoSize(lptstrFilename, nullptr);
94+
final lptstrFilename = filePath.toPcwstr();
95+
final sizeResult = GetFileVersionInfoSize(lptstrFilename, null);
96+
final dwLen = sizeResult.value;
9297

9398
final lpData = calloc<BYTE>(dwLen); // freed by the dispose() method
94-
final lpSubBlock = TEXT(r'\VarFileInfo\Translation');
99+
final lpSubBlock = r'\VarFileInfo\Translation'.toPcwstr();
95100
final lpTranslate = calloc<Pointer<LANGANDCODEPAGE>>();
96101
final puLen = calloc<UINT>();
97102
try {
98-
if (GetFileVersionInfo(lptstrFilename, NULL, dwLen, lpData) == 0) {
99-
throw WindowsException(HRESULT_FROM_WIN32(GetLastError()));
103+
final infoResult = GetFileVersionInfo(lptstrFilename, dwLen, lpData);
104+
if (!infoResult.value) {
105+
throw WindowsException(infoResult.error.toHRESULT());
100106
}
101107

102-
if (VerQueryValue(lpData, lpSubBlock, lpTranslate.cast(), puLen) == 0) {
103-
throw WindowsException(HRESULT_FROM_WIN32(GetLastError()));
108+
if (!VerQueryValue(lpData, lpSubBlock, lpTranslate.cast(), puLen)) {
109+
throw WindowsException(GetLastError().toHRESULT());
104110
}
105111
return FileVersionInfoData(lpBlock: lpData, lpLang: lpTranslate.value);
106112
} finally {

packages/package_info_plus/package_info_plus/lib/src/package_info_plus_linux.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class PackageInfoPlusLinuxPlugin extends PackageInfoPlatform {
4545
}
4646

4747
Future<({DateTime? created, DateTime? modified})> _getExeAttributes(
48-
String exePath) async {
48+
String exePath,
49+
) async {
4950
try {
5051
final statResult = await Process.run(
5152
'stat',
@@ -58,8 +59,9 @@ class PackageInfoPlusLinuxPlugin extends PackageInfoPlatform {
5859
return await _fallbackAttributes(exePath);
5960
}
6061

61-
final String stdout =
62-
statResult.stdout is String ? statResult.stdout : '';
62+
final String stdout = statResult.stdout is String
63+
? statResult.stdout
64+
: '';
6365

6466
if (stdout.split(',').length != 2) {
6567
return await _fallbackAttributes(exePath);
@@ -74,24 +76,24 @@ class PackageInfoPlusLinuxPlugin extends PackageInfoPlatform {
7476
);
7577
final modificationTime = _parseSecondsString(modificationMillis);
7678

77-
return (
78-
created: creationTime,
79-
modified: modificationTime,
80-
);
79+
return (created: creationTime, modified: modificationTime);
8180
} catch (_) {
8281
return (created: null, modified: null);
8382
}
8483
}
8584

8685
Future<({DateTime created, DateTime modified})> _fallbackAttributes(
87-
String exePath) async {
86+
String exePath,
87+
) async {
8888
final modifiedTime = await File(exePath).lastModified();
8989

9090
return (created: modifiedTime, modified: modifiedTime);
9191
}
9292

93-
DateTime? _parseSecondsString(String? secondsString,
94-
{bool allowZero = true}) {
93+
DateTime? _parseSecondsString(
94+
String? secondsString, {
95+
bool allowZero = true,
96+
}) {
9597
if (secondsString == null) {
9698
return null;
9799
}

packages/package_info_plus/package_info_plus/lib/src/package_info_plus_web.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PackageInfoPlusWebPlugin extends PackageInfoPlatform {
1717

1818
/// Create plugin with http client and asset manager for testing purposes.
1919
PackageInfoPlusWebPlugin([this._client, AssetManager? assetManagerMock])
20-
: _assetManager = assetManagerMock ?? assetManager;
20+
: _assetManager = assetManagerMock ?? assetManager;
2121

2222
/// Registers this class as the default instance of [PackageInfoPlatform].
2323
static void registerWith(Registrar registrar) {
@@ -48,18 +48,19 @@ class PackageInfoPlusWebPlugin extends PackageInfoPlatform {
4848

4949
// Add file and cachebuster query
5050
return uri.replace(
51-
query: 'cachebuster=$cacheBuster',
52-
pathSegments: [...segments, 'version.json']);
51+
query: 'cachebuster=$cacheBuster',
52+
pathSegments: [...segments, 'version.json'],
53+
);
5354
}
5455

5556
@override
5657
Future<PackageInfoData> getAll({String? baseUrl}) async {
5758
final int cacheBuster = clock.now().millisecondsSinceEpoch;
5859
final Map<String, dynamic> versionMap =
5960
await _getVersionMap(baseUrl, cacheBuster) ??
60-
await _getVersionMap(_assetManager.baseUrl, cacheBuster) ??
61-
await _getVersionMap(web.window.document.baseURI, cacheBuster) ??
62-
{};
61+
await _getVersionMap(_assetManager.baseUrl, cacheBuster) ??
62+
await _getVersionMap(web.window.document.baseURI, cacheBuster) ??
63+
{};
6364

6465
return PackageInfoData(
6566
appName: versionMap['app_name'] ?? '',

packages/package_info_plus/package_info_plus/pubspec.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,24 @@ flutter:
2828
dartPluginClass: PackageInfoPlusWindowsPlugin
2929

3030
dependencies:
31-
ffi: ^2.0.1
31+
clock: ^1.1.2
32+
ffi: ^2.2.0
3233
flutter:
3334
sdk: flutter
3435
flutter_web_plugins:
3536
sdk: flutter
36-
http: ">=0.13.5 <2.0.0"
37-
meta: ^1.8.0
38-
path: ^1.8.2
37+
http: ^1.6.0
38+
meta: ^1.17.0
3939
package_info_plus_platform_interface: ^3.2.1
40-
web: ">=0.5.0 <2.0.0"
41-
win32: ">=5.5.3 <7.0.0"
42-
clock: ^1.1.1
40+
path: ^1.9.1
41+
web: ^1.1.1
42+
win32: ^6.0.0
4343

4444
dev_dependencies:
45-
flutter_lints: ">=4.0.0 <6.0.0"
45+
flutter_lints: ^6.0.0
4646
flutter_test:
4747
sdk: flutter
48-
test: ^1.22.0
4948

5049
environment:
51-
sdk: ">=3.3.0 <4.0.0"
52-
flutter: ">=3.19.0"
50+
sdk: ">=3.11.0 <4.0.0"
51+
flutter: ">=3.41.0"

packages/package_info_plus/package_info_plus/test/package_info_plus_windows_test.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ void main() {
6262
const missingFile = 'C:\\macos\\system128\\colonel.dll';
6363

6464
expect(
65-
() => FileVersionInfo(missingFile),
66-
throwsA(isArgumentError.having(
65+
() => FileVersionInfo(missingFile),
66+
throwsA(
67+
isArgumentError.having(
6768
(e) => e.message,
6869
'message',
6970
startsWith('File not present'),
70-
)));
71+
),
72+
),
73+
);
7174
});
7275
}

packages/package_info_plus/package_info_plus/test/package_info_test.dart

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,48 @@ void main() {
2020
final mockUpdateTime = now;
2121

2222
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
23-
.setMockMethodCallHandler(
24-
channel,
25-
(MethodCall methodCall) async {
26-
log.add(methodCall);
27-
switch (methodCall.method) {
28-
case 'getAll':
29-
return <String, dynamic>{
30-
'appName': 'package_info_example',
31-
'buildNumber': '1',
32-
'packageName': 'io.flutter.plugins.packageinfoexample',
33-
'version': '1.0',
34-
'installerStore': null,
35-
'installTime': mockInstallTime.millisecondsSinceEpoch.toString(),
36-
'updateTime': mockUpdateTime.millisecondsSinceEpoch.toString(),
37-
};
38-
default:
39-
assert(false);
40-
return null;
41-
}
42-
},
43-
);
23+
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
24+
log.add(methodCall);
25+
switch (methodCall.method) {
26+
case 'getAll':
27+
return <String, dynamic>{
28+
'appName': 'package_info_example',
29+
'buildNumber': '1',
30+
'packageName': 'io.flutter.plugins.packageinfoexample',
31+
'version': '1.0',
32+
'installerStore': null,
33+
'installTime': mockInstallTime.millisecondsSinceEpoch.toString(),
34+
'updateTime': mockUpdateTime.millisecondsSinceEpoch.toString(),
35+
};
36+
default:
37+
assert(false);
38+
return null;
39+
}
40+
});
4441

4542
tearDown(() {
4643
log.clear();
4744
});
4845

49-
test('fromPlatform', () async {
50-
final info = await PackageInfo.fromPlatform();
51-
expect(info.appName, 'package_info_example');
52-
expect(info.buildNumber, '1');
53-
expect(info.packageName, 'io.flutter.plugins.packageinfoexample');
54-
expect(info.version, '1.0');
55-
expect(info.installerStore, null);
56-
expect(info.installTime, mockInstallTime);
57-
expect(info.updateTime, mockUpdateTime);
58-
expect(
59-
log,
60-
<Matcher>[
61-
isMethodCall('getAll', arguments: null),
62-
],
63-
);
64-
}, onPlatform: {
65-
'linux':
66-
const Skip('PackageInfoPlus on Linux does not use platform channels'),
67-
});
46+
test(
47+
'fromPlatform',
48+
() async {
49+
final info = await PackageInfo.fromPlatform();
50+
expect(info.appName, 'package_info_example');
51+
expect(info.buildNumber, '1');
52+
expect(info.packageName, 'io.flutter.plugins.packageinfoexample');
53+
expect(info.version, '1.0');
54+
expect(info.installerStore, null);
55+
expect(info.installTime, mockInstallTime);
56+
expect(info.updateTime, mockUpdateTime);
57+
expect(log, <Matcher>[isMethodCall('getAll', arguments: null)]);
58+
},
59+
onPlatform: {
60+
'linux': const Skip(
61+
'PackageInfoPlus on Linux does not use platform channels',
62+
),
63+
},
64+
);
6865

6966
test('Mock initial values', () async {
7067
PackageInfo.setMockInitialValues(

packages/package_info_plus/package_info_plus_platform_interface/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/
77
dependencies:
88
flutter:
99
sdk: flutter
10-
meta: ^1.8.0
11-
plugin_platform_interface: ^2.1.4
10+
meta: ^1.17.0
11+
plugin_platform_interface: ^2.1.8
1212

1313
dev_dependencies:
1414
flutter_test:
1515
sdk: flutter
16-
mockito: ^5.4.0
17-
flutter_lints: ">=4.0.0 <6.0.0"
16+
mockito: ^5.6.4
17+
flutter_lints: ^6.0.0
1818

1919
environment:
20-
sdk: ">=2.18.0 <4.0.0"
21-
flutter: ">=3.3.0"
20+
sdk: ">=3.11.0 <4.0.0"
21+
flutter: ">=3.46.0"

0 commit comments

Comments
 (0)