Skip to content

Commit

Permalink
smart多语言问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HO-COOH committed Mar 5, 2023
1 parent 6dfbc63 commit ee27507
Show file tree
Hide file tree
Showing 40 changed files with 178 additions and 28 deletions.
17 changes: 6 additions & 11 deletions DiskInfoLibWinRT/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,27 @@ namespace winrt::DiskInfoLibWinRT::implementation
continue;

SmartAttribute attr{};
attr.Id = std::format(L"{:0>2x}", attribute.Id);
attr.Id = std::format(L"{:0>2X}", attribute.Id);

wchar_t buf[256]{};
static winrt::hstring const path{ [] {
TCHAR currentExePath[MAX_PATH]{};
GetModuleFileName(NULL, currentExePath, MAX_PATH);
std::wstring_view view{ currentExePath };
view = view.substr(0, view.rfind(L"\\"));
return std::wstring{ view } + LR"(\Assets\English.lang)";
}() };

GetPrivateProfileStringFx(
original.SmartKeyName,
attr.Id.data(),
L"",
buf,
sizeof(buf) / sizeof(wchar_t),
path.data()
PathManager::CurrentLangPath().data()
);

attr.Name = buf;

std::wstring rawValue;
for (auto byte : std::ranges::reverse_view(attribute.RawValue))
rawValue += std::format(L"{:0>2x}", byte);
rawValue += std::format(L"{:0>2X}", byte);

attr.RawValue = rawValue;
attr.Threshold = std::format(L"{:0>2x}", threshold.ThresholdValue);
attr.Threshold = std::format(L"{:0>2X}", threshold.ThresholdValue);

info.Attributes().Append(winrt::box_value(attr));
}
Expand All @@ -166,6 +159,8 @@ namespace winrt::DiskInfoLibWinRT::implementation
GraphData::GetInstance().SetDataSource(CAtaSmart::get_instance().vars);
m_DefaultLangPath = PathManager::GetInstance().DefaultLangPath().data();
m_CurrentLangPath = PathManager::GetInstance().CurrentLangPath().data();
MessageBox(NULL, m_DefaultLangPath, L"", 0);
MessageBox(NULL, m_CurrentLangPath, L"", 0);
}

void Class::UpdateAll()
Expand Down
63 changes: 54 additions & 9 deletions DiskInfoLibWinRT/PathManager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#include "PathManager.h"

#include <winrt/Windows.System.UserProfile.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <Windows.h>
#include <ShlObj_core.h>
#include <filesystem>
#include <format>
#include <winrt/Windows.Globalization.h>
#include <ranges>

PathManager::PathManager()
{
Expand All @@ -15,6 +20,18 @@ PathManager::PathManager()
}
}

std::wstring const& PathManager::CurrentExeDir()
{
static std::wstring const path{ [] {
TCHAR currentExePath[MAX_PATH]{};
GetModuleFileName(NULL, currentExePath, MAX_PATH);
std::wstring_view view{ currentExePath };
view = view.substr(0, view.rfind(L"\\"));
return std::wstring{ view };
}() };
return path;
}

winrt::hstring PathManager::SmartDir()
{
if (m_appData)
Expand All @@ -25,18 +42,46 @@ winrt::hstring PathManager::SmartDir()
return winrt::hstring{ path } + LR"(\Diskinfo\smart\)";
}

winrt::hstring PathManager::DefaultLangPath()
winrt::hstring const& PathManager::DefaultLangPath()
{
if (m_appData)
return m_appData.LocalFolder().Path() + LR"(\Assets\English.lang)";
return LR"(C:\Users\Peter\Desktop\diskInfo\DiskTools\DiskTools\Assets\English.lang)";
static winrt::hstring result{ CurrentExeDir() + LR"(\Assets\CrystalDiskInfoLangFiles\Simplified Chinese.lang)" };
return result;
}

winrt::hstring PathManager::CurrentLangPath()
static auto ToLower(std::string_view original)
{
if (m_appData)
return m_appData.LocalFolder().Path() + LR"(\Assets\English.lang)";
return LR"(C:\Users\Peter\Desktop\diskInfo\DiskTools\DiskTools\Assets\English.lang)";
std::string ret;
std::ranges::transform(original, std::back_inserter(ret), [](int c) {return std::tolower(c); });
return ret;
}

winrt::hstring const& PathManager::CurrentLangPath()
{
static winrt::hstring result{
[]
{
/*
Match the current Display Language for "best" effort, eg:
currentLanaguageName File
English (United State) English
Chinese (Simpified, China) Simplified
Chinese (Traditional, Hong Kong SAR) Traditional
*/
auto const currentLanguageCode = winrt::Windows::System::UserProfile::GlobalizationPreferences::Languages().GetAt(0);
auto const currentLanguageName = winrt::to_string(winrt::Windows::Globalization::Language{ currentLanguageCode }.DisplayName());

std::string const currentLanguageNameLower = ToLower(currentLanguageName);
for (auto iter : std::filesystem::directory_iterator{ CurrentExeDir() + LR"(\Assets\CrystalDiskInfoLangFiles)" })
{
auto path = iter.path();
auto fileName = path.stem().string();
if (currentLanguageNameLower.find(ToLower(fileName)) != std::string::npos)
return winrt::to_hstring(path.string());
}
return DefaultLangPath();
}()
};
return result;
}


Expand Down
6 changes: 4 additions & 2 deletions DiskInfoLibWinRT/PathManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ class PathManager
winrt::Windows::Storage::ApplicationData m_appData{ nullptr };

PathManager();

static std::wstring const& CurrentExeDir();
public:
winrt::hstring SmartDir();
winrt::hstring DefaultLangPath();
winrt::hstring CurrentLangPath();
static winrt::hstring const& DefaultLangPath();
static winrt::hstring const& CurrentLangPath();

static PathManager& GetInstance();
};
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
120 changes: 114 additions & 6 deletions DiskTools/DiskTools/DiskTools.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -19,14 +19,14 @@
<PropertyGroup>
<CsWinRTIncludes>DiskInfoLibWinRT</CsWinRTIncludes>
<CsWinRTGeneratedFilesDir>$(OutDir)</CsWinRTGeneratedFilesDir>
<GenerateAppInstallerFile>True</GenerateAppInstallerFile>
<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<PackageCertificateThumbprint>0E886E609DD7C496A3DE178F7DD1DF16B72DD2EF</PackageCertificateThumbprint>
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Never</AppxBundle>
<GenerateTestArtifacts>False</GenerateTestArtifacts>
<AppxBundle>Auto</AppxBundle>
<AppInstallerUri>E:\</AppInstallerUri>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
</PropertyGroup>
Expand Down Expand Up @@ -64,7 +64,115 @@
</ItemGroup>

<ItemGroup>
<Content Update="Assets\English.lang">
<Content Update="Assets\CrystalDiskInfoLangFiles\Arabic.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Armenian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Azeri.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Bulgarian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Czech.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Danish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Dutch.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\English.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Filipino.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Finnish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\French.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Galician.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\German.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\German2.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Greek.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Hungarian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Italian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Japanese.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Korean.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Lithuanian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Norwegian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Polish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Portuguese.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Romanian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Russian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Serbian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Simplified.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Slovak.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Slovenian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Spanish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Swedish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Thai.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Traditional.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Turkish.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Ukrainian.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\CrystalDiskInfoLangFiles\Vietnamese.lang">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Assets\icon.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down

0 comments on commit ee27507

Please sign in to comment.