Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.Storage;
- using Windows.Storage.Pickers;
- 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;
- // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
- namespace App2
- {
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- }
- public async void WriteFile()
- {
- StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("ProgSchedule.txt");
- }
- private ObservableCollection<string> _items = new ObservableCollection<string>();
- public ObservableCollection<string> Items
- {
- get { return this._items; }
- }
- public static async Task<string> WriteToSettings(string filename, string[] text)
- {
- //Create dataFile.txt in LocalFolder and write “My text” to it
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- //await localFolder.CreateFileAsync(@"ProgSchedule.txt");
- var file = await ApplicationData.Current.LocalFolder.GetFileAsync(@"ProgSchedule.txt");
- StorageFile sampleFile = await localFolder.GetFileAsync(@"ProgSchedule.txt");
- foreach (string i in text)
- {
- await FileIO.AppendTextAsync(sampleFile, i);
- }
- return "kek";
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- public static async Task<string> ReadStringFromLocalFile(string filename, int actualLine)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- {
- // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
- IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
- return fileContent[actualLine];
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- public static async Task<string> DeleteLineFromFile(string filename, int actualLine)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- {
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
- IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
- fileContent.RemoveAt(actualLine);
- await FileIO.WriteLinesAsync(sampleFile, fileContent);
- //string really = await refreshItemList();
- return "okey dokey";
- }
- public async Task<string> refreshItemList()
- {
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
- IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
- Items.Clear();
- foreach (string readline in fileContent)
- {
- int idx = readline.LastIndexOf('|');
- string appName = readline.Substring(idx + 1);
- Items.Add(appName);
- }
- return "ok";
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- public async Task<string> ReplaceLineFromFile(string filename, int actualLine, string textToReplace)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- {
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
- IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
- fileContent[actualLine] = textToReplace;
- await FileIO.WriteLinesAsync(sampleFile, fileContent);
- //string really = await refreshItemList();
- return "okey dokey";
- }
- protected override async void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- StorageFile sampleFile = await localFolder.GetFileAsync("ProgSchedule.txt");
- IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFile);
- Items.Clear();
- foreach (string readline in fileContent)
- {
- int idx = readline.LastIndexOf('|');
- string appName = readline.Substring(idx + 1);
- Items.Add(appName);
- }
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- }
- private async void Button_Click_1Async(object sender, RoutedEventArgs e)
- {
- string hello = await DeleteLineFromFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
- }
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- }
- private async void Button_Click_3Async(object sender, RoutedEventArgs e)
- {
- string path = Path.Text;
- string name = Name.Text;
- string time = timePick.Time.ToString(@"hh\:mm");
- bool ignore = isIgnore.IsOn;
- bool restart = isRestart.IsOn;
- string strIgnore = Convert.ToString(Convert.ToInt32(ignore));
- string strRestart = Convert.ToString(Convert.ToInt32(restart));
- string parameters = '"' + time + '"' + strIgnore + '|' + strRestart + '|' + path + '|' + name;
- string noneed = await ReplaceLineFromFile(@"ProgSchedule.txt", itemListView.SelectedIndex, parameters);
- }
- private async void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
- string[] appTime = readline.Split('"');
- TimeSpan systemTime = TimeSpan.Parse(appTime[1]);
- readline = readline.Substring(7);
- string[] splitString = readline.Split('|');
- bool ignore = false;
- bool restart = false;
- if (readline[0].Equals('1'))
- {
- ignore = true;
- }
- if (readline[0].Equals('0'))
- {
- ignore = false;
- }
- if (readline[2].Equals('1'))
- {
- restart = true;
- }
- if (readline[2].Equals('0'))
- {
- restart = false;
- }
- timePick.Time = systemTime;
- Path.Text = splitString[2];
- Name.Text = splitString[3];
- isIgnore.IsOn = ignore;
- isRestart.IsOn = restart;
- }
- private void isRestart_Toggled(object sender, RoutedEventArgs e)
- {
- }
- private void isIgnore_Toggled(object sender, RoutedEventArgs e)
- {
- }
- private async void Button_Click_2Async(object sender, RoutedEventArgs e)
- {
- string[] toWrite = new string[] { '"' + "00:00" + '"' + "|0|0|C:\\|newapp"};
- string cmon = await WriteToSettings(@"ProgSchedule.txt", toWrite);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement