diff options
Diffstat (limited to 'protocols/Telegram/tdlib/td/example/uwp')
7 files changed, 85 insertions, 62 deletions
diff --git a/protocols/Telegram/tdlib/td/example/uwp/README.md b/protocols/Telegram/tdlib/td/example/uwp/README.md index e7bb9b821b..c0b4de723f 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/README.md +++ b/protocols/Telegram/tdlib/td/example/uwp/README.md @@ -7,22 +7,22 @@ This is an example of building TDLib SDK for Universal Windows Platform and an e * Download and install Microsoft Visual Studio 2015+ with Windows 10 SDK. We recommend to use the latest available versions of Microsoft Visual Studio and Windows 10 SDK. * Download and install [CMake](https://cmake.org/download/). * Install [vcpkg](https://github.com/Microsoft/vcpkg#quick-start) or update it to the latest version using `vcpkg update` and following received instructions. -* Install `zlib` and `openssl` for all UWP architectures using `vcpkg`: +* Install `zlib` and `openssl` for all UWP architectures and `gperf` for x86 using `vcpkg`: ``` -C:\src\vcpkg> .\vcpkg.exe install openssl:arm-uwp openssl:x64-uwp openssl:x86-uwp zlib:arm-uwp zlib:x64-uwp zlib:x86-uwp +cd <path to vcpkg> +.\vcpkg.exe install gperf:x86-windows openssl:arm-uwp openssl:arm64-uwp openssl:x64-uwp openssl:x86-uwp zlib:arm-uwp zlib:arm64-uwp zlib:x64-uwp zlib:x86-uwp ``` * (Optional. For XML documentation generation.) Download [PHP](https://windows.php.net/download#php-7.2). Add the path to php.exe to the PATH environment variable. -* Download and install [gperf](https://sourceforge.net/projects/gnuwin32/files/gperf/3.0.1/). Add the path to gperf.exe to the PATH environment variable. * Download and install [7-Zip](http://www.7-zip.org/download.html) archiver, which is used by the `build.ps1` script to create a Telegram.Td.UWP Visual Studio Extension. Add the path to 7z.exe to the PATH environment variable. Alternatively `build.ps1` supports compressing using [WinRAR](https://en.wikipedia.org/wiki/WinRAR) with option `-compress winrar` and compressing using [zip](http://gnuwin32.sourceforge.net/packages/zip.htm) with `-compress zip`. -* Build `TDLib` using provided `build.ps1` script (TDLib should be built 6 times for multiple platforms in Debug and Release configurations, so it make take few hours). Pass path to vcpkg.exe as `-vcpkg-root` argument: +* Build `TDLib` using provided `build.ps1` script (TDLib should be built 6 times for multiple platforms in Debug and Release configurations, so it make take few hours). Pass path to vcpkg.exe as `-vcpkg-root` argument, for example: ``` -powershell -ExecutionPolicy ByPass .\build.ps1 -vcpkg_root C:\src\vcpkg +powershell -ExecutionPolicy ByPass .\build.ps1 -vcpkg_root C:\vcpkg ``` -If you need to restart the build from scratch, call `.\build.ps1 -mode clean` first. +If you need to restart the build from scratch, call `.\build.ps1 -vcpkg_root C:\vcpkg -mode clean` first. * Install Visual Studio Extension "TDLib for Universal Windows Platform" located at `build-uwp\vsix\tdlib.vsix`, which was created on the previous step by `build.ps1` script. -Now `TDLib` can be freely used from any UWP project, built in Visual Studio. +Now `TDLib` can be used from any UWP project, built in Visual Studio. ## Example of usage -The `app/` directory contains a simple example of a C# application for Universal Windows Platform. Just open it with Visual Studio 2015 or 2017 and run. +The `app/` directory contains a simple example of a C# application for Universal Windows Platform. Just open it with Visual Studio 2015 or later and run. diff --git a/protocols/Telegram/tdlib/td/example/uwp/app/App.xaml.cs b/protocols/Telegram/tdlib/td/example/uwp/app/App.xaml.cs index 0ed0f96812..5bfc66a30f 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/app/App.xaml.cs +++ b/protocols/Telegram/tdlib/td/example/uwp/app/App.xaml.cs @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) diff --git a/protocols/Telegram/tdlib/td/example/uwp/app/MainPage.xaml.cs b/protocols/Telegram/tdlib/td/example/uwp/app/MainPage.xaml.cs index 9bdf5070ee..4c42e27676 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/app/MainPage.xaml.cs +++ b/protocols/Telegram/tdlib/td/example/uwp/app/MainPage.xaml.cs @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -18,7 +18,7 @@ namespace TdApp { public System.Collections.ObjectModel.ObservableCollection<string> Items { get; set; } - private static MyClientResultHandler _handler; + private MyClientResultHandler _handler; public MainPage() { @@ -27,31 +27,25 @@ namespace TdApp Items = new System.Collections.ObjectModel.ObservableCollection<string>(); _handler = new MyClientResultHandler(this); + Td.Client.Execute(new TdApi.SetLogVerbosityLevel(0)); + Td.Client.Execute(new TdApi.SetLogStream(new TdApi.LogStreamFile(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "log"), 1 << 27, false))); + Td.Client.SetLogMessageCallback(100, LogMessageCallback); System.Threading.Tasks.Task.Run(() => { - try - { - Td.Log.SetFilePath(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "log")); - _client = Td.Client.Create(_handler); - var parameters = new TdApi.TdlibParameters(); - parameters.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path; - parameters.UseSecretChats = true; - parameters.UseMessageDatabase = true; - parameters.ApiId = 94575; - parameters.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2"; - parameters.SystemLanguageCode = "en"; - parameters.DeviceModel = "en"; - parameters.SystemVersion = "en"; - parameters.ApplicationVersion = "1.0.0"; - _client.Send(new TdApi.SetTdlibParameters(parameters), null); - _client.Send(new TdApi.CheckDatabaseEncryptionKey(), null); - _client.Run(); - } - catch (Exception ex) - { - Print(ex.ToString()); - } + Td.Client.Run(); }); + + _client = Td.Client.Create(_handler); + var request = new TdApi.SetTdlibParameters(); + request.DatabaseDirectory = Windows.Storage.ApplicationData.Current.LocalFolder.Path; + request.UseSecretChats = true; + request.UseMessageDatabase = true; + request.ApiId = 94575; + request.ApiHash = "a3406de8d171bb422bb6ddf3bbd800e2"; + request.SystemLanguageCode = "en"; + request.DeviceModel = "Desktop"; + request.ApplicationVersion = "1.0.0"; + _client.Send(request, null); } public void Print(String str) @@ -62,7 +56,15 @@ namespace TdApp }); } - private static Td.Client _client; + private void LogMessageCallback(int verbosity_level, String str) + { + if (verbosity_level < 0) { + return; + } + Print(verbosity_level + ": " + str); + } + + private Td.Client _client; private void AcceptCommand(String command) { @@ -92,13 +94,25 @@ namespace TdApp { var args = command.Split(" ".ToCharArray(), 2); AcceptCommand(command); - _client.Send(new TdApi.SetAuthenticationPhoneNumber(args[1], false, false), _handler); + _client.Send(new TdApi.SetAuthenticationPhoneNumber(args[1], null), _handler); + } + else if (command.StartsWith("sae")) + { + var args = command.Split(" ".ToCharArray(), 2); + AcceptCommand(command); + _client.Send(new TdApi.SetAuthenticationEmailAddress(args[1]), _handler); + } + else if (command.StartsWith("caec")) + { + var args = command.Split(" ".ToCharArray(), 2); + AcceptCommand(command); + _client.Send(new TdApi.CheckAuthenticationEmailCode(new TdApi.EmailAddressAuthenticationCode(args[1])), _handler); } else if (command.StartsWith("cac")) { var args = command.Split(" ".ToCharArray(), 2); AcceptCommand(command); - _client.Send(new TdApi.CheckAuthenticationCode(args[1], String.Empty, String.Empty), _handler); + _client.Send(new TdApi.CheckAuthenticationCode(args[1]), _handler); } else if (command.StartsWith("cap")) { @@ -106,6 +120,12 @@ namespace TdApp AcceptCommand(command); _client.Send(new TdApi.CheckAuthenticationPassword(args[1]), _handler); } + else if (command.StartsWith("alm")) + { + var args = command.Split(" ".ToCharArray(), 3); + AcceptCommand(command); + _client.Send(new TdApi.AddLogMessage(Int32.Parse(args[1]), args[2]), _handler); + } else if (command.StartsWith("gco")) { var args = command.Split(" ".ToCharArray(), 2); @@ -116,7 +136,7 @@ namespace TdApp { var args = command.Split(" ".ToCharArray(), 2); AcceptCommand(command); - _client.Send(new TdApi.DownloadFile(Int32.Parse(args[1]), 1), _handler); + _client.Send(new TdApi.DownloadFile(Int32.Parse(args[1]), 1, 0, 0, false), _handler); } else if (command.StartsWith("bench")) { diff --git a/protocols/Telegram/tdlib/td/example/uwp/app/Properties/AssemblyInfo.cs b/protocols/Telegram/tdlib/td/example/uwp/app/Properties/AssemblyInfo.cs index 99e2b83bea..2e008d1a29 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/app/Properties/AssemblyInfo.cs +++ b/protocols/Telegram/tdlib/td/example/uwp/app/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("App2")] -[assembly: AssemblyCopyright("Copyright © 2015-2018")] +[assembly: AssemblyCopyright("Copyright © 2015-2022")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -26,4 +26,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: ComVisible(false)]
\ No newline at end of file +[assembly: ComVisible(false)] diff --git a/protocols/Telegram/tdlib/td/example/uwp/app/TdApp.csproj b/protocols/Telegram/tdlib/td/example/uwp/app/TdApp.csproj index b3d1d944d1..2b0de8df3d 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/app/TdApp.csproj +++ b/protocols/Telegram/tdlib/td/example/uwp/app/TdApp.csproj @@ -88,7 +88,7 @@ <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain> </PropertyGroup> <ItemGroup> - <!-- A reference to the entire .Net Framework and Windows SDK are automatically included --> + <!-- A reference to the entire .NET Framework and Windows SDK are automatically included --> <Content Include="ApplicationInsights.config"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> diff --git a/protocols/Telegram/tdlib/td/example/uwp/build.ps1 b/protocols/Telegram/tdlib/td/example/uwp/build.ps1 index 71156b0a2d..587945a4b2 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/build.ps1 +++ b/protocols/Telegram/tdlib/td/example/uwp/build.ps1 @@ -2,17 +2,23 @@ param ( [string]$vcpkg_root = $(throw "-vcpkg_root=<path to vcpkg> is required"), [string]$arch = "", [string]$mode = "all", - [string]$compress = "7z" + [string]$compress = "7z", + [switch]$release_only = $false ) $ErrorActionPreference = "Stop" $vcpkg_root = Resolve-Path $vcpkg_root $vcpkg_cmake="${vcpkg_root}\scripts\buildsystems\vcpkg.cmake" -$arch_list = @( "x86", "x64", "arm" ) +$arch_list = @( "x86", "x64", "ARM" ) if ($arch) { $arch_list = @(, $arch) } +$config_list = @( "Debug", "Release" ) +if ($release_only) { + $config_list = @(, "RelWithDebInfo") +} +$targets = @{ Debug = "Debug"; Release = "Retail"; RelWithDebInfo = "CommonConfiguration"} $td_root = Resolve-Path "../.." @@ -35,7 +41,7 @@ function prepare { cd build-native - cmake $td_root -DCMAKE_TOOLCHAIN_FILE="$vcpkg_cmake" -DTD_ENABLE_DOTNET=1 + cmake -A Win32 -DCMAKE_TOOLCHAIN_FILE="$vcpkg_cmake" -DTD_ENABLE_DOTNET=ON "$td_root" CheckLastExitCode cmake --build . --target prepare_cross_compiling CheckLastExitCode @@ -47,7 +53,7 @@ function config { New-Item -ItemType Directory -Force -Path build-uwp cd build-uwp - ForEach($arch in $arch_list) { + ForEach ($arch in $arch_list) { echo "Config Arch = [$arch]" New-Item -ItemType Directory -Force -Path $arch cd $arch @@ -56,7 +62,7 @@ function config { if ($arch -eq "x86") { $fixed_arch = "win32" } - cmake "$td_root" -A $fixed_arch -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_TOOLCHAIN_FILE="$vcpkg_cmake" -DTD_ENABLE_DOTNET=1 + cmake -A $fixed_arch -DCMAKE_SYSTEM_VERSION="10.0" -DCMAKE_SYSTEM_NAME="WindowsStore" -DCMAKE_TOOLCHAIN_FILE="$vcpkg_cmake" -DTD_ENABLE_DOTNET=ON "$td_root" CheckLastExitCode cd .. } @@ -66,11 +72,12 @@ function config { function build { cd build-uwp - ForEach($arch in $arch_list) { + ForEach ($arch in $arch_list) { echo "Build Arch = [$arch]" cd $arch - cmake --build . --config Release --target tddotnet - cmake --build . --config Debug --target tddotnet + ForEach ($config in $config_list) { + cmake --build . --config $config --target tddotnet + } cd .. } cd .. @@ -85,23 +92,19 @@ function export { cp '../`[Content_Types`].xml' vsix cp ../LICENSE_1_0.txt vsix - ForEach($arch in $arch_list) { - New-Item -ItemType Directory -Force -Path vsix/DesignTime/Debug/${arch} - New-Item -ItemType Directory -Force -Path vsix/DesignTime/Retail/${arch} - New-Item -ItemType Directory -Force -Path vsix/Redist/Debug/${arch} - New-Item -ItemType Directory -Force -Path vsix/Redist/Retail/${arch} + ForEach ($arch in $arch_list) { New-Item -ItemType Directory -Force -Path vsix/References/CommonConfiguration/${arch} + ForEach ($config in $config_list) { + $target = $targets[$config] - cp ${arch}/Debug/* -include "LIBEAY*","SSLEAY*","zlib*" vsix/Redist/Debug/${arch}/ - cp ${arch}/Release/* -include "LIBEAY*","SSLEAY*","zlib*" vsix/Redist/Retail/${arch}/ + New-Item -ItemType Directory -Force -Path vsix/DesignTime/${target}/${arch} + cp ${arch}/${config}/Telegram.Td.lib vsix/DesignTime/${target}/${arch}/ - cp ${arch}/Debug/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/Debug/${arch}/ - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.lib" vsix/DesignTime/Retail/${arch}/ + New-Item -ItemType Directory -Force -Path vsix/Redist/${target}/${arch} + cp ${arch}/${config}/* -include "SSLEAY*","LIBEAY*","libcrypto*","libssl*","zlib*","Telegram.Td.pdb","Telegram.Td.dll" vsix/Redist/${target}/${arch}/ - cp ${arch}/Debug/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/Debug/${arch}/ - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pdb","*.dll" vsix/Redist/Retail/${arch}/ - - cp ${arch}/Release/* -filter "Telegram.Td.*" -include "*.pri","*.winmd","*.xml" vsix/References/CommonConfiguration/${arch}/ + cp ${arch}/${config}/* -include "Telegram.Td.pri","Telegram.Td.winmd","Telegram.Td.xml" vsix/References/CommonConfiguration/${arch}/ + } } cd vsix diff --git a/protocols/Telegram/tdlib/td/example/uwp/extension.vsixmanifest b/protocols/Telegram/tdlib/td/example/uwp/extension.vsixmanifest index cfcfdb57af..28cacff65f 100644 --- a/protocols/Telegram/tdlib/td/example/uwp/extension.vsixmanifest +++ b/protocols/Telegram/tdlib/td/example/uwp/extension.vsixmanifest @@ -1,6 +1,6 @@ <PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"> <Metadata> - <Identity Id="Telegram.Td.UWP" Version="1.2.0" Language="en-US" Publisher="Telegram LLC" /> + <Identity Id="Telegram.Td.UWP" Version="1.8.8" Language="en-US" Publisher="Telegram LLC" /> <DisplayName>TDLib for Universal Windows Platform</DisplayName> <Description>TDLib is a library for building Telegram clients</Description> <MoreInfo>https://core.telegram.org/tdlib</MoreInfo> |