Example #1
0
        private void OnSaveInfo()
        {
            App.DisplayStatusMessage("Starting saving of info.", StatusMessageType.USER);

            var dialog = new SaveFileDialog();

            dialog.DefaultExt       = IdentificationFile.EXT;      //gets long extensions to work properly when they are added to a filename when saved
            dialog.Filter           = IdentificationFile.FILTER;
            dialog.OverwritePrompt  = true;
            dialog.Title            = "Select Location to Save Info File";
            dialog.InitialDirectory = Directory.GetCurrentDirectory();            //TODO: remember last used directory

            if (dialog.ShowDialog() == true)
            {
                //replace .xml with .Info.xml
                var actualFileName = ExtensionFixer.SwitchToLongExtension(dialog.FileName, IdentificationFile.SHORT_EXT, IdentificationFile.EXT);

                try
                {
                    using (var fileStream = new FileStream(actualFileName, FileMode.Create, FileAccess.Write))
                    {
                        var infoFile = new IdentificationFile();

                        foreach (var entry in ECUInfo)
                        {
                            infoFile.IdentificationValues.Add(entry);
                        }

                        App.SerializeToXML(fileStream, infoFile);
                        App.DisplayStatusMessage("Successfully saved info to file.", StatusMessageType.USER);
                    }
                }
                catch
                {
                    App.DisplayStatusMessage("Failed to save info to file.", StatusMessageType.USER);
                }
            }
            else
            {
                App.DisplayStatusMessage("Cancelling saving of info.", StatusMessageType.USER);
            }
        }
Example #2
0
        private void OnSaveDeviceInfo()
        {
            string deviceSaveLocation = ECUFlasher.Properties.Settings.Default.SaveDeviceInfoLocation;

            if (string.IsNullOrEmpty(deviceSaveLocation))
            {
                deviceSaveLocation = Directory.GetCurrentDirectory();
            }

            var dialog = new SaveFileDialog();

            dialog.DefaultExt       = FTDIDevicesFile.EXT;      //gets long extensions to work properly when they are added to a filename when saved
            dialog.Filter           = FTDIDevicesFile.FILTER;
            dialog.InitialDirectory = deviceSaveLocation;
            dialog.OverwritePrompt  = true;
            dialog.Title            = "Select Where to Save Device Info File";

            if (dialog.ShowDialog() == true)
            {
                bool successfullySavedInfo = false;

                //replace .xml with .FTDIDevices.xml
                var actualFileName = ExtensionFixer.SwitchToLongExtension(dialog.FileName, FTDIDevicesFile.SHORT_EXT, FTDIDevicesFile.EXT);

                try
                {
                    using (var fStream = new FileStream(actualFileName, FileMode.Create, FileAccess.Write, FileShare.Write))
                    {
                        var devicesFile = new FTDIDevicesFile();
                        devicesFile.Devices.AddRange(FTDIDevices);

                        SerializeToXML(fStream, devicesFile);

                        successfullySavedInfo = true;
                    }
                }
                catch (Exception e)
                {
                    DisplayStatusMessage("Encountered exception while saving device info to file: " + e.Message, StatusMessageType.USER);
                    successfullySavedInfo = false;
                }

                if (!String.IsNullOrEmpty(dialog.FileName))
                {
                    DirectoryInfo dirInfo = Directory.GetParent(dialog.FileName);

                    if (dirInfo != null)
                    {
                        ECUFlasher.Properties.Settings.Default.SaveDeviceInfoLocation = dirInfo.FullName;
                    }
                }

                if (successfullySavedInfo)
                {
                    DisplayStatusMessage("Successfully saved device info to file.", StatusMessageType.USER);
                }
                else
                {
                    DisplayStatusMessage("Failed to save device info to file.", StatusMessageType.USER);
                }
            }
        }