Forráskód Böngészése

Fix default conf; add minimal conf

bdbai 2 éve
szülő
commit
5d93a32fe7

+ 3 - 3
Maple.App/Config/default.conf

@@ -30,14 +30,14 @@ tls-ws-amux-trojan2 = trojan, 1.0.0.1, 443, password=123456, sni=www.domain.com,
 
 [Proxy Group]
 # fallback 等效于 failover
-Fallback = fallback, Trojan, VMessWSS, SS, interval=600, timeout=5
+Fallback = fallback, Trojan, VMessWSS, SS, check-interval=600, fail-timeout=5
 
 # url-test 等效于 failover=false 的 failover
-UrlTest = url-test, Trojan, VMessWSS, SS, interval=600, timeout=5
+UrlTest = url-test, Trojan, VMessWSS, SS, check-interval=600, fail-timeout=5
 
 Failover = failover, Trojan, VMessWSS, SS, health-check=true, check-interval=600, fail-timeout=5, failover=true
 Tryall = tryall, Trojan, VMessWSS, delay-base=0
-Random = random, Trojan, VMessWSS
+Random = static, Trojan, VMessWSS
 
 [Rule]
 # 执行文件目录当中必需有 `site.dat` 文件

+ 12 - 0
Maple.App/Config/minimal.conf

@@ -0,0 +1,12 @@
+[General]
+loglevel = error
+tun = auto
+dns-server = 223.5.5.5, 114.114.114.114
+
+[Proxy]
+# Define your proxy server here
+server1 = ss, 1.2.3.4, 8485, encrypt-method=chacha20-ietf-poly1305, password=123456
+
+[Rule]
+# `server1` refers to one of the defined proxy server
+FINAL, server1

+ 9 - 10
Maple.App/MainPage.cpp

@@ -106,14 +106,9 @@ namespace winrt::Maple_App::implementation
         co_return configItem.as<IStorageFolder>();
     }
 
-    IAsyncOperation<StorageFile> MainPage::CopyDefaultConfig(const IStorageFolder& configFolder, const hstring& desiredName)
+    IAsyncOperation<StorageFile> MainPage::CopyDefaultConfig(const IStorageFolder& configFolder, std::wstring_view path, const hstring& desiredName)
     {
-        const auto& defaultConfigSrc = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{ L"ms-appx:///Config/default.conf" });
-        co_return co_await defaultConfigSrc.CopyAsync(configFolder, desiredName, NameCollisionOption::GenerateUniqueName);
-    }
-    IAsyncOperation<StorageFile> MainPage::CopyDefaultJsonConfig(const IStorageFolder& configFolder, const hstring& desiredName)
-    {
-        const auto& defaultConfigSrc = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{ L"ms-appx:///Config/default.json" });
+        const auto& defaultConfigSrc = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{ path });
         co_return co_await defaultConfigSrc.CopyAsync(configFolder, desiredName, NameCollisionOption::GenerateUniqueName);
     }
 
@@ -124,7 +119,7 @@ namespace winrt::Maple_App::implementation
         m_configFolder = co_await InitializeConfigFolder();
         auto configFiles = co_await m_configFolder.GetFilesAsync();
         if (configFiles.Size() == 0) {
-            const auto& defaultConfigDst = co_await CopyDefaultConfig(m_configFolder, L"default.conf");
+            const auto& defaultConfigDst = co_await CopyDefaultConfig(m_configFolder, DEFAULT_CONF_FILE_PATH, L"default.conf");
             appData.LocalSettings().Values().Insert(CONFIG_PATH_SETTING_KEY, box_value(defaultConfigDst.Path()));
             configFiles = co_await m_configFolder.GetFilesAsync();
         }
@@ -295,10 +290,14 @@ namespace winrt::Maple_App::implementation
             const auto& buttonText = sender.as<MenuFlyoutItem>().Text();
             StorageFile newFile{ nullptr };
             if (buttonText == L"Conf") {
-                newFile = co_await CopyDefaultConfig(m_configFolder, L"New Config.conf");
+                newFile = co_await CopyDefaultConfig(m_configFolder, DEFAULT_CONF_FILE_PATH, L"New Config.conf");
             }
             else if (buttonText == L"JSON") {
-                newFile = co_await CopyDefaultJsonConfig(m_configFolder, L"New Config.json");
+                newFile = co_await CopyDefaultConfig(m_configFolder, DEFAULT_JSON_FILE_PATH, L"New Config.json");
+            }
+            else if (buttonText == L"Minimal")
+            {
+                newFile = co_await CopyDefaultConfig(m_configFolder, DEFAULT_MINIMAL_FILE_PATH, L"New Config.conf");
             }
             else {
                 co_return;

+ 4 - 2
Maple.App/MainPage.h

@@ -25,6 +25,9 @@ namespace winrt::Maple_App::implementation
 
     static const hstring CONFIG_PATH_SETTING_KEY = L"CONFIG_PATH";
     static const hstring NETIF_SETTING_KEY = L"NETIF";
+    static const std::wstring_view DEFAULT_CONF_FILE_PATH = L"ms-appx:///Config/default.conf";
+    static const std::wstring_view DEFAULT_JSON_FILE_PATH = L"ms-appx:///Config/default.json";
+    static const std::wstring_view DEFAULT_MINIMAL_FILE_PATH = L"ms-appx:///Config/minimal.conf";
     std::string getNormalizedExtentionFromPath(const winrt::hstring& path);
     struct MainPage : MainPageT<MainPage>
     {
@@ -80,8 +83,7 @@ namespace winrt::Maple_App::implementation
 
         static IAsyncAction NotifyUser(const hstring& message);
         static IAsyncOperation<IStorageFolder> InitializeConfigFolder();
-        static IAsyncOperation<StorageFile> CopyDefaultConfig(const IStorageFolder& configFolder, const hstring& desiredName);
-        static IAsyncOperation<StorageFile> CopyDefaultJsonConfig(const IStorageFolder& configFolder, const hstring& desiredName);
+        static IAsyncOperation<StorageFile> CopyDefaultConfig(const IStorageFolder& configFolder, std::wstring_view path, const hstring& desiredName);
 
         void RequestRenameItem(const Maple_App::ConfigViewModel& item);
         void SetAsDefault(const Maple_App::ConfigViewModel& item);

+ 1 - 0
Maple.App/MainPage.xaml

@@ -149,6 +149,7 @@
                                         <MenuFlyout Placement="Top">
                                             <MenuFlyoutItem Text="Conf" Click="ConfigCreateMenuItem_Click"/>
                                             <MenuFlyoutItem Text="JSON" Click="ConfigCreateMenuItem_Click"/>
+                                            <MenuFlyoutItem Text="Minimal" Click="ConfigCreateMenuItem_Click"/>
                                             <MenuFlyoutSeparator/>
                                             <MenuFlyoutItem Text="Import…" Click="ConfigImportMenuItem_Click"/>
                                         </MenuFlyout>

+ 12 - 1
Maple.App/MonacoEditPage.cpp

@@ -162,7 +162,18 @@ namespace winrt::Maple_App::implementation
                 {
                     path = path.replace(pos, strlen(CONFIG_ROOT_VIRTUAL_HOST), configDirPath);
                 }
-                auto const file{ co_await StorageFile::GetFileFromPathAsync(to_hstring(path)) };
+                StorageFile file{ nullptr };
+                try {
+                    file = co_await StorageFile::GetFileFromPathAsync(to_hstring(path));
+                }
+                catch (hresult_error const& hr)
+                {
+                    if (hr.code().value == 0x80070002)
+                    {
+                        co_return;
+                    }
+                    throw;
+                }
                 std::string const data{ doc["text"] };
                 auto const fstream = co_await file.OpenAsync(FileAccessMode::ReadWrite, StorageOpenOptions::AllowOnlyReaders);
                 fstream.Size(0);

+ 0 - 1
Maple.Task/VpnPlugin.h

@@ -20,7 +20,6 @@ namespace winrt::Maple_Task::implementation
         void Encapsulate(Windows::Networking::Vpn::VpnChannel const& channel, Windows::Networking::Vpn::VpnPacketBufferList const& packets, Windows::Networking::Vpn::VpnPacketBufferList const& encapulatedPackets);
         void Decapsulate(Windows::Networking::Vpn::VpnChannel const& channel, Windows::Networking::Vpn::VpnPacketBuffer const& encapBuffer, Windows::Networking::Vpn::VpnPacketBufferList const& decapsulatedPackets, Windows::Networking::Vpn::VpnPacketBufferList const& controlPacketsToSend);
 
-    private:
         void ConnectCore(Windows::Networking::Vpn::VpnChannel const& channel);
         void StopLeaf();