Browse Source

Support mmdb/v2ray dlc

bdbai 4 năm trước cách đây
mục cha
commit
51f812d88f

+ 17 - 0
Maple.App/DatPage.cpp

@@ -0,0 +1,17 @@
+#include "pch.h"
+#include "DatPage.h"
+#if __has_include("DatPage.g.cpp")
+#include "DatPage.g.cpp"
+#endif
+
+using namespace winrt;
+using namespace Windows::UI::Xaml;
+
+namespace winrt::Maple_App::implementation
+{
+    DatPage::DatPage()
+    {
+        InitializeComponent();
+    }
+
+}

+ 19 - 0
Maple.App/DatPage.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "DatPage.g.h"
+
+namespace winrt::Maple_App::implementation
+{
+    struct DatPage : DatPageT<DatPage>
+    {
+        DatPage();
+
+    };
+}
+
+namespace winrt::Maple_App::factory_implementation
+{
+    struct DatPage : DatPageT<DatPage, implementation::DatPage>
+    {
+    };
+}

+ 8 - 0
Maple.App/DatPage.idl

@@ -0,0 +1,8 @@
+namespace Maple_App
+{
+    [default_interface]
+    runtimeclass DatPage : Windows.UI.Xaml.Controls.Page
+    {
+        DatPage();
+    }
+}

+ 21 - 0
Maple.App/DatPage.xaml

@@ -0,0 +1,21 @@
+<Page
+    x:Class="Maple_App.DatPage"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Maple_App"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    mc:Ignorable="d">
+
+    <StackPanel Orientation="Vertical" Padding="16, 16, 0, 0">
+        <TextBlock TextWrapping="Wrap">
+            <Run>Use</Run>
+            <Run FontFamily="Consolas">EXTERNAL</Run>
+            <Run>directives in a configuration file to make use of a V2Ray Domain List Community database. For more information, see</Run>
+            <Hyperlink NavigateUri="https://github.com/eycorsican/leaf/blob/master/README.zh.md#site">
+                https://github.com/eycorsican/leaf/blob/master/README.zh.md#site
+            </Hyperlink>
+            <Run>.</Run>
+        </TextBlock>
+    </StackPanel>
+</Page>

+ 30 - 8
Maple.App/MainPage.cpp

@@ -7,6 +7,14 @@
 
 namespace winrt::Maple_App::implementation
 {
+    std::string getNormalizedExtentionFromPath(const winrt::hstring& path) {
+        auto ext = std::filesystem::path(std::wstring_view(path)).extension().string();
+        std::transform(ext.begin(), ext.end(), ext.begin(), [](const auto ch) {
+            return static_cast<char>(std::tolower(ch));
+            });
+        return ext;
+    }
+
     MainPage::MainPage()
     {
         InitializeComponent();
@@ -115,6 +123,11 @@ namespace winrt::Maple_App::implementation
 
     void MainPage::SetAsDefault(const Maple_App::ConfigViewModel& item)
     {
+        const auto name = getNormalizedExtentionFromPath(item.Name());
+        if (name != ".conf" && name != ".json") {
+            NotifyUser(L"A valid configuration file must end with .conf or .json.");
+            return;
+        }
         ApplicationData::Current().LocalSettings().Values().Insert(CONFIG_PATH_SETTING_KEY, box_value(item.File().Path()));
         m_defaultConfig.IsDefault(false);
         item.IsDefault(true);
@@ -198,7 +211,7 @@ namespace winrt::Maple_App::implementation
         const auto& renameDialog = RenameDialog();
         const auto& item = renameDialog.DataContext().as<Maple_App::ConfigViewModel>();
         if (item == nullptr) {
-            return;
+            co_return;
         }
         co_await item.Rename(RenameDialogText().Text());
         if (item == m_defaultConfig) {
@@ -276,8 +289,20 @@ namespace winrt::Maple_App::implementation
 
     void MainPage::ConfigListView_SelectionChanged(IInspectable const&, SelectionChangedEventArgs const& e)
     {
+        const auto& item = e.AddedItems().First().Current();
+        auto targetPage = xaml_typename<EditPage>();
+        const auto& config = item.try_as<Maple_App::ConfigViewModel>();
+        if (config != nullptr) {
+            const auto ext = getNormalizedExtentionFromPath(config.Name());
+            if (ext == ".mmdb") {
+                targetPage = xaml_typename<MmdbPage>();
+            }
+            else if (ext == ".dat") {
+                targetPage = xaml_typename<DatPage>();
+            }
+        }
         MainContentFrame().BackStack().Clear();
-        MainContentFrame().Navigate(xaml_typename<EditPage>(), e.AddedItems().First().Current());
+        MainContentFrame().Navigate(targetPage, item);
     }
 
     void MainPage::ConfigListView_DragItemsStarting(IInspectable const&, DragItemsStartingEventArgs const& e)
@@ -311,7 +336,7 @@ namespace winrt::Maple_App::implementation
         const auto& dataView = e.DataView();
         if (static_cast<uint32_t>(e.AllowedOperations() & DataPackageOperation::Copy) == 0
             || !dataView.Contains(StandardDataFormats::StorageItems())) {
-            return;
+            co_return;
         }
 
         const auto& items = co_await dataView.GetStorageItemsAsync();
@@ -321,11 +346,8 @@ namespace winrt::Maple_App::implementation
             if (file == nullptr) {
                 continue;
             }
-            auto ext = std::filesystem::path(std::wstring_view(file.Path())).extension().string();
-            std::transform(ext.begin(), ext.end(), ext.begin(), [](const auto ch) {
-                return static_cast<char>(std::tolower(ch));
-                });
-            if (ext != ".json" && ext != ".conf") {
+            auto ext = getNormalizedExtentionFromPath(file.Path());
+            if (ext != ".json" && ext != ".conf" && ext != ".mmdb" && ext != ".dat") {
                 continue;
             }
             const auto& newFile = co_await file.CopyAsync(targetDir, file.Name(), NameCollisionOption::GenerateUniqueName);

+ 30 - 0
Maple.App/Maple.App.vcxproj

@@ -125,10 +125,18 @@
       <DependentUpon>Converter\DateTimeConverter.idl</DependentUpon>
       <SubType>Code</SubType>
     </ClInclude>
+    <ClInclude Include="DatPage.h">
+      <DependentUpon>DatPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClInclude>
     <ClInclude Include="EditPage.h">
       <DependentUpon>EditPage.xaml</DependentUpon>
       <SubType>Code</SubType>
     </ClInclude>
+    <ClInclude Include="MmdbPage.h">
+      <DependentUpon>MmdbPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClInclude>
     <ClInclude Include="Model\ConfigViewModel.h">
       <DependentUpon>Model\ConfigViewModel.idl</DependentUpon>
       <SubType>Code</SubType>
@@ -149,12 +157,18 @@
     <ApplicationDefinition Include="App.xaml">
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Page Include="DatPage.xaml">
+      <SubType>Designer</SubType>
+    </Page>
     <Page Include="EditPage.xaml">
       <SubType>Designer</SubType>
     </Page>
     <Page Include="MainPage.xaml">
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="MmdbPage.xaml">
+      <SubType>Designer</SubType>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <AppxManifest Include="Package.appxmanifest">
@@ -219,10 +233,18 @@
       <DependentUpon>Converter\DateTimeConverter.idl</DependentUpon>
       <SubType>Code</SubType>
     </ClCompile>
+    <ClCompile Include="DatPage.cpp">
+      <DependentUpon>DatPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClCompile>
     <ClCompile Include="EditPage.cpp">
       <DependentUpon>EditPage.xaml</DependentUpon>
       <SubType>Code</SubType>
     </ClCompile>
+    <ClCompile Include="MmdbPage.cpp">
+      <DependentUpon>MmdbPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </ClCompile>
     <ClCompile Include="Model\ConfigViewModel.cpp">
       <DependentUpon>Model\ConfigViewModel.idl</DependentUpon>
       <SubType>Code</SubType>
@@ -249,6 +271,10 @@
     <Midl Include="Converter\DateTimeConverter.idl">
       <SubType>Designer</SubType>
     </Midl>
+    <Midl Include="DatPage.idl">
+      <DependentUpon>DatPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Midl>
     <Midl Include="EditPage.idl">
       <DependentUpon>EditPage.xaml</DependentUpon>
       <SubType>Code</SubType>
@@ -256,6 +282,10 @@
     <Midl Include="MainPage.idl">
       <DependentUpon>MainPage.xaml</DependentUpon>
     </Midl>
+    <Midl Include="MmdbPage.idl">
+      <DependentUpon>MmdbPage.xaml</DependentUpon>
+      <SubType>Code</SubType>
+    </Midl>
     <Midl Include="Model\ConfigViewModel.idl">
       <SubType>Designer</SubType>
     </Midl>

+ 2 - 0
Maple.App/Maple.App.vcxproj.filters

@@ -172,6 +172,8 @@
   <ItemGroup>
     <Page Include="EditPage.xaml" />
     <Page Include="MainPage.xaml" />
+    <Page Include="MmdbPage.xaml" />
+    <Page Include="DatPage.xaml" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="Assets">

+ 17 - 0
Maple.App/MmdbPage.cpp

@@ -0,0 +1,17 @@
+#include "pch.h"
+#include "MmdbPage.h"
+#if __has_include("MmdbPage.g.cpp")
+#include "MmdbPage.g.cpp"
+#endif
+
+using namespace winrt;
+using namespace Windows::UI::Xaml;
+
+namespace winrt::Maple_App::implementation
+{
+    MmdbPage::MmdbPage()
+    {
+        InitializeComponent();
+    }
+
+}

+ 19 - 0
Maple.App/MmdbPage.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include "MmdbPage.g.h"
+
+namespace winrt::Maple_App::implementation
+{
+    struct MmdbPage : MmdbPageT<MmdbPage>
+    {
+        MmdbPage();
+
+    };
+}
+
+namespace winrt::Maple_App::factory_implementation
+{
+    struct MmdbPage : MmdbPageT<MmdbPage, implementation::MmdbPage>
+    {
+    };
+}

+ 8 - 0
Maple.App/MmdbPage.idl

@@ -0,0 +1,8 @@
+namespace Maple_App
+{
+    [default_interface]
+    runtimeclass MmdbPage : Windows.UI.Xaml.Controls.Page
+    {
+        MmdbPage();
+    }
+}

+ 30 - 0
Maple.App/MmdbPage.xaml

@@ -0,0 +1,30 @@
+<Page
+    x:Class="Maple_App.MmdbPage"
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:local="using:Maple_App"
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+    mc:Ignorable="d">
+
+    <StackPanel Orientation="Vertical" Padding="16, 16, 0, 0">
+        <TextBlock TextWrapping="Wrap">
+            <Run>Use</Run>
+            <Run FontFamily="Consolas">GEOIP</Run>
+            <Run>or</Run>
+            <Run FontFamily="Consolas">EXTERNAL</Run>
+            <Run>directives in a configuration file to make use of a</Run>
+            <Run FontFamily="Consolas">geo.mmdb</Run>
+            <Run>database. For more information, see</Run>
+            <Hyperlink NavigateUri="https://github.com/eycorsican/leaf/blob/master/README.zh.md">
+                https://github.com/eycorsican/leaf/blob/master/README.zh.md
+            </Hyperlink>
+            <Run>.</Run>
+        </TextBlock>
+        <TextBlock Margin="0, 8, 0, 0" TextWrapping="Wrap">
+            <Run>This product includes GeoLite2 data created by MaxMind, available from</Run>
+            <Hyperlink NavigateUri="https://www.maxmind.com">https://www.maxmind.com</Hyperlink>
+            <Run>.</Run>
+        </TextBlock>
+    </StackPanel>
+</Page>

+ 9 - 2
Maple.Task/VpnPlugin.cpp

@@ -77,8 +77,15 @@ namespace winrt::Maple_Task::implementation
             return;
         }
 
-        const auto& confPathW = ApplicationData::Current().LocalSettings().Values().TryLookup(CONFIG_PATH_SETTING_KEY).try_as<hstring>().value_or(L"");
-        const auto& outNetifW = ApplicationData::Current().LocalSettings().Values().TryLookup(NETIF_SETTING_KEY).try_as<hstring>().value_or(L"");
+        const auto& configFolderPath = Windows::Storage::ApplicationData::Current().LocalFolder().CreateFolderAsync(L"config", CreationCollisionOption::OpenIfExists).get().Path();
+        if (!SetEnvironmentVariable(L"ASSET_LOCATION", configFolderPath.data())) {
+            channel.TerminateConnection(L"Failed to set asset location: " + winrt::to_hstring((uint32_t)GetLastError()));
+            return;
+        }
+
+        const auto& localProperties = ApplicationData::Current().LocalSettings().Values();
+        const auto& confPathW = localProperties.TryLookup(CONFIG_PATH_SETTING_KEY).try_as<hstring>().value_or(L"");
+        const auto& outNetifW = localProperties.TryLookup(NETIF_SETTING_KEY).try_as<hstring>().value_or(L"");
         const auto& confPath = winrt::to_string(confPathW);
         const auto& outNetif = winrt::to_string(outNetifW);
         thread_local std::vector<HostName> dnsHosts{};

+ 1 - 1
leaf

@@ -1 +1 @@
-Subproject commit 5b4ce62e236a9014ef4de0f7bc1b6e469c7d7d77
+Subproject commit 1303763fd33659402a5e970152bce914f6d67319