コード例 #1
0
        /// <summary>
        /// Updates data in file and save changes
        /// </summary>
        /// <param name="updatedFileData"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool SaveUpdatedFile(List <string> updatedFileData, string filePath)
        {
            try
            {
                // Clear file
                using (var stream = new FileStream(filePath, FileMode.Truncate))
                {
                    // Add new content to file
                    using (var writer = new StreamWriter(stream))
                    {
                        foreach (string s in updatedFileData)
                        {
                            writer.WriteLine(s);
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                // If any error occure save it to log file
                LogsManager.SaveErrorToLogFile(ex.Message);

                return(false);
            }

            return(false);
        }
コード例 #2
0
        // Loads data from first file
        public List <string> LoadAndReadFile(string filePath)
        {
            try
            {
                // Read in a file line-by-line, and store it all in a List.
                List <string> list = new List <string>();

                using (StreamReader reader = new StreamReader(filePath, Encoding.UTF8, true))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        list.Add(line); // Add to list.
                    }
                }

                return(list);
            }
            catch (Exception ex)
            {
                // If any error occure save it to log file
                LogsManager.SaveErrorToLogFile(ex.Message);
            }

            return(new List <string>());
        }
コード例 #3
0
        public bool SaveFile(List <string> fileData)
        {
            // creates save fiale dialog object and set its properties
            Microsoft.Win32.SaveFileDialog saveDialog = new Microsoft.Win32.SaveFileDialog();

            saveDialog.Title  = "Zapisz wygenerowaną łatkę";
            saveDialog.Filter = "PATCH files (*.patch)|*.patch";

            try
            {
                // show save filedialog
                if (saveDialog.ShowDialog() == true)
                {
                    // save file if path was choosen correctly
                    using (StreamWriter writer = new StreamWriter(saveDialog.FileName))
                    {
                        foreach (string s in fileData)
                        {
                            writer.WriteLine(s);
                        }
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                // If any error occure save it to log file
                LogsManager.SaveErrorToLogFile(ex.Message);

                return(false);
            }

            return(false);
        }