Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube/Pages/SettingsPages/Translate.xaml.cs
T
Michael Gordeev ba02a37760 Settings rebuild
2018-08-01 19:04:12 +03:00

126 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage.Pickers;
using Windows.Storage;
using System.Net.Mail;
using System.Net;
using Windows.UI.Popups;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace FoxTube.Pages.SettingsPages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Translate : Page
{
ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
int selectedLanguage;
public Translate()
{
this.InitializeComponent();
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
LangList.Items.Add(culture.DisplayName);
}
private async void export_Click(object sender, RoutedEventArgs e)
{
FileSavePicker picker = new FileSavePicker();
picker.CommitButtonText = "Export";
picker.DefaultFileExtension = ".xml";
picker.SuggestedFileName = "foxtube_langpack_" + CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage];
picker.SuggestedStartLocation = PickerLocationId.Desktop;
picker.FileTypeChoices.Add("Language pack scheme", new List<string>() { ".xml" });
StorageFile file = await picker.PickSaveFileAsync();
if(file != null)
await FileIO.WriteTextAsync(file, GetPackage(selectedLanguage));
}
private void LangList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
selectedLanguage = LangList.SelectedIndex;
greenResult.Visibility = Visibility.Collapsed;
denied.Visibility = Visibility.Collapsed;
if (settings.Values[CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage] + "_sent"] == null)
{
export.IsEnabled = true;
upload.IsEnabled = true;
submitNotification.Visibility = Visibility.Visible;
}
else
{
export.IsEnabled = false;
upload.IsEnabled = false;
denied.Visibility = Visibility.Visible;
}
}
private async void upload_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = new FileOpenPicker()
{
CommitButtonText = "Upload",
SuggestedStartLocation = PickerLocationId.Desktop
};
picker.FileTypeFilter.Clear();
picker.FileTypeFilter.Add(".xml");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
MailMessage msg = new MailMessage();
msg.To.Add("foxgameofficial+foxtube@gmail.com");
msg.From = new MailAddress("foxgameofficial+foxtube@gmail.com");
msg.Subject = "FoxTube language pack contribution";
msg.Body = string.Format("Language: {0}\nLanguage code: {1}", CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage].EnglishName, CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage]);
msg.Attachments.Add(new Attachment(file.Path));
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = SecretsVault.EmailCredential;
upload.IsEnabled = false;
export.IsEnabled = false;
uploadingProgress.Visibility = Visibility.Visible;
try
{
client.Send(msg);
greenResult.Visibility = Visibility.Visible;
submitNotification.Visibility = Visibility.Collapsed;
settings.Values.Add(CultureInfo.GetCultures(CultureTypes.AllCultures)[selectedLanguage] + "_sent", true);
}
catch
{
MessageDialog message = new MessageDialog("We were unable to send your feedback due to connection problems or internal server error. Please, try again later.", "Failed to send your feedback");
await message.ShowAsync();
export.IsEnabled = true;
upload.IsEnabled = true;
}
uploadingProgress.Visibility = Visibility.Collapsed;
}
}
public string GetPackage(int cultureIndex)
{
return "langpack";
}
}
}