Esempio n. 1
0
        private void BtnConvert_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtConvertOld.Text) || !string.IsNullOrWhiteSpace(txtConvertNew.Text))
            {
                var path = AppService.ShowOpenFileDialog(opts, "txt files (*.txt)|*.txt");

                if (!string.IsNullOrWhiteSpace(path))
                {
                    var lines    = FileIoService.GetStringCollectionFromFile(path);
                    var newLines = new List <string>();

                    foreach (string line in lines)
                    {
                        newLines.Add(line.Replace(txtConvertOld.Text.Single(), txtConvertNew.Text.Single()));
                    }

                    FileIoService.SaveLineCollectionToFile(newLines, path);
                    AppService.LogLine("Converted file: " + path);
                }
                else
                {
                    MessageBox.Show("Path is required to convert file");
                }
            }
            else
            {
                MessageBox.Show("Must have a value in both delimiter boxes");
            }
        }
Esempio n. 2
0
        private void BtnLoad_Click(object sender, RoutedEventArgs e)
        {
            var fileName = AppService.ShowOpenFileDialog(opts, "txt files (*.txt)|*.txt");

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                if (fileName.Split('.').Last().ToUpper().Equals("TXT"))
                {
                    var itemObject = GetCurrentItemType();

                    itemObject = FileIoService.LoadObjectFromFile(itemObject, fileName, false);
                    if (itemObject.IsNothing())
                    {
                        LogLine("Item type mismatch. Select correct item type from drop down or add a new item via Options");
                    }
                    else
                    {
                        LoadItem(itemObject, fileName);
                        LogLine($"Loaded \"{fileName}\" as {itemObject.GetType().ToString()}");
                    }
                }
                else
                {
                    AppService.LogLine($"Items must be in a TXT file format");
                }
            }
        }
Esempio n. 3
0
        public static string GetTermsP2(ProgramOptions opts)
        {
            var termLines = FileIoService.GetStringCollectionFromFile(opts.DefaultTermsPathP2);
            var sb        = new StringBuilder();

            foreach (string line in termLines)
            {
                sb.AppendLine(line);
            }
            return(sb.ToString());
        }
Esempio n. 4
0
        public static void InitApplication()
        {
            //init options file
            FileIoService.CreateFileIfDoesntExist(GlobalConstants.OptionsFilePath);

            //init templates directory
            if (!Directory.Exists(GlobalConstants.TemplatesPath))
            {
                Directory.CreateDirectory(GlobalConstants.TemplatesPath);
                LogLine("Created templates directory");
            }
        }
Esempio n. 5
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            generatedTemplatePath = AppService.ShowSaveDialog(opts, "html", "desc");

            if (!string.IsNullOrWhiteSpace(generatedTemplatePath))
            {
                FileIoService.SaveSingleLineToFile(generatedTemplate, generatedTemplatePath);

                var endOfDirectoryPath = generatedTemplatePath.LastIndexOf('\\');
                generatedTemplateDirectory = generatedTemplatePath.Substring(0, endOfDirectoryPath);
                LogLine($"Saved template HTML to \"{generatedTemplatePath}\"");
                btnOpenBrowser.IsEnabled = true;
                btnOpenHtmlDir.IsEnabled = true;
                RefreshOptions();
            }
        }
Esempio n. 6
0
        private void BtnSaveLog_Click(object sender, RoutedEventArgs e)
        {
            var path = AppService.ShowSaveDialog(opts, "txt", $"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}_{DateTime.Now.Hour}-{DateTime.Now.Minute}_log");

            if (!string.IsNullOrWhiteSpace(path))
            {
                var logs = new List <string>();
                foreach (var log in lstLog.Items)
                {
                    logs.Add(log.ToString());
                }

                FileIoService.SaveLineCollectionToFile(logs, path);
                RefreshOptions();
                LogLine($"Saved logs to \"{path}\"");
            }
        }
Esempio n. 7
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            //TODO: add basic and advanced combination on option flag
            c.BasicCPU       = txtBasicCPU.Text;
            c.BasicRAM       = txtBasicRAM.Text;
            c.BasicHDD       = txtBasicHDD.Text;
            c.BasicOS        = txtBasicOS.Text;
            c.CPUType        = txtCPUType.Text;
            c.RAMCapacity    = txtRAMCapacity.Text;
            c.RAMType        = txtRAMType.Text;
            c.HDDSize        = txtHDDSize.Text;
            c.CPUSpeed       = txtCPUSpeed.Text;
            c.CPUCores       = txtCPUCores.Text;
            c.CPUThreads     = txtCPUThreads.Text;
            c.HDDQuantity    = txtHDDQuantity.Text;
            c.HDDSpeed       = txtHDDSpeed.Text;
            c.GFX            = txtGFX.Text;
            c.ScreenSize     = txtScreenSize.Text;
            c.ScreenRes      = txtScreenRes.Text;
            c.ScreenType     = txtScreenType.Text;
            c.Battery        = txtBattery.Text;
            c.OSVersion      = txtOSVersion.Text;
            c.Webcam         = txtWebcam.Text;
            c.OtherDrives    = txtOtherDrives.Text;
            c.Nics           = txtNics.Text;
            c.ItemTitle      = txtItemTitle.Text;
            c.ItemLongDescP1 = txtItemLongDescP1.Text;
            c.ItemLongDescP2 = txtItemLongDescP2.Text;
            c.HDDInterface   = txtHDDInterface.Text;

            if (string.IsNullOrWhiteSpace(path))
            {
                path = AppService.ShowSaveDialog(opts, "txt", "computer");
            }

            if (!string.IsNullOrWhiteSpace(path))
            {
                FileIoService.SaveObjectToFile(c, path);
                AppService.RefreshItem(c, path);
                AppService.RefreshMainWindowOptions();
                AppService.LogLine($"Saved item to \"{path}\"");
                this.Close();
            }
        }
Esempio n. 8
0
        public static List <string> GenerateFromTemplate(ProgramOptions opts, Object item)
        {
            var templateLines = FileIoService.GetStringCollectionFromFile(opts.SelectedTemplate);
            var itemProps     = item.GetType().GetProperties();
            var newLines      = new List <string>();

            foreach (string line in templateLines)
            {
                if (line.Contains("{"))
                {
                    var firstPos      = line.IndexOf('{');
                    var lastPos       = line.IndexOf('}');
                    var propToReplace = line.Substring(firstPos + 1, lastPos - firstPos - 1);
                    var bracketedProp = $"{{{propToReplace}}}";

                    var itemProp = itemProps.FirstOrDefault(x => x.Name.Equals(propToReplace));

                    if (itemProp != null)
                    {
                        newLines.Add(line.Replace(bracketedProp, itemProp.GetValue(item).ToString()).Trim());
                    }
                    else if (itemProp == null && propToReplace.ToUpper().Contains("TERMSP1"))
                    {
                        newLines.Add(line.Replace(bracketedProp, GetTermsP1(opts)));
                    }
                    else if (itemProp == null && propToReplace.ToUpper().Contains("TERMSP2"))
                    {
                        newLines.Add(line.Replace(bracketedProp, GetTermsP2(opts)));
                    }
                    else
                    {
                        LogLine($"Item {item.GetType().ToString()} does not contain property {propToReplace}");
                        newLines.Add(@"<div style='display:none;'>Error replacing property " + propToReplace + "</div>");
                    }
                }
                else if (!string.IsNullOrWhiteSpace(line))
                {
                    newLines.Add(line.Trim());
                }
            }

            return(newLines);
        }
Esempio n. 9
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            part.ItemTitle      = txtItemTitle.Text;
            part.ItemLongDescP1 = txtItemLongDescP1.Text;
            part.ItemLongDescP2 = txtItemLongDescP2.Text;

            if (string.IsNullOrWhiteSpace(path))
            {
                path = AppService.ShowSaveDialog(opts, "txt", "part");
            }
            else
            {
                FileIoService.SaveObjectToFile(part, path);
                AppService.RefreshItem(part, path);
                AppService.RefreshMainWindowOptions();
                AppService.LogLine($"Saved item to \"{path}\"");
                this.Close();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// saves current item in its present state to its present path and unloads from memory
        /// </summary>
        private void UnloadItem()
        {
            if (itemLoaded)
            {
                FileIoService.SaveObjectToFile(currentItem, lblActiveItem.Content.ToString());
                currentItem       = null;
                itemLoaded        = false;
                btnEdit.IsEnabled = false;
                btnOpenItemDirectory.IsEnabled = false;
                cboItemType.IsEnabled          = true;
                lblActiveItem.Content          = "None";
                btnUnload.IsEnabled            = false;

                CheckCanGenerate();
                UnloadGeneratedOutput();

                LogLine("Closed item");
            }
        }
Esempio n. 11
0
        public static char GetDelimiter()
        {
            var fileLines   = new List <string>();
            var fileExisted = FileIoService.CreateFileIfDoesntExist(GlobalConstants.DelimiterFilePath);

            if (fileExisted)
            {
                fileLines = FileIoService.GetStringCollectionFromFile(GlobalConstants.DelimiterFilePath);
            }

            //if the delimiter file does not exist, create it and add default delimiter
            if (fileLines.Count == 0)
            {
                FileIoService.SaveSingleLineToFile("|", GlobalConstants.DelimiterFilePath);
                LogLine("Delimiter file was created with default value |. To change, go to program directory and update character in delimiter.txt and restart application");
                return(GetDelimiter());
            }
            else
            {
                return(fileLines.First().First());
            }
        }
Esempio n. 12
0
 public static void SaveProgramOptions(ProgramOptions opts)
 {
     FileIoService.SaveObjectToFile(opts, GlobalConstants.OptionsFilePath);
 }
Esempio n. 13
0
        public static ProgramOptions GetProgramOptions()
        {
            var opts = new ProgramOptions();

            return((ProgramOptions)FileIoService.LoadObjectFromFile(opts, GlobalConstants.OptionsFilePath, true));
        }