Пример #1
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (ImportFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                Texture = new Bitmap(ImportFileDialog.FileName);

                if (Texture != null)
                {
                    BaseZoom = Math.Min((float)PreviewPanel.ClientSize.Width / Texture.Width,
                                        (float)PreviewPanel.ClientSize.Height / Texture.Height);

                    PropertiesTextBox.Text = "[" + Texture.PixelFormat +
                                             "] " + Texture.Width + " x " + Texture.Height;
                    ExportButton.Enabled = true;
                }
                else
                {
                    ExportButton.Enabled = false;
                }

                RepairOffset();
                PreviewPanel.Invalidate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error: Can not import texture.");
            }
        }
Пример #2
0
        private void ImportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ImportFileDialog.ShowDialog(this);
            string path = ImportFileDialog.FileName;

            try
            {
                string import_path = ResourceExplorer.CurrentDirectory;
                string name        = Path.GetFileNameWithoutExtension(path);
                int    i           = 0;
                if (File.Exists(Path.Combine(import_path, name)) ||
                    Directory.Exists(Path.Combine(import_path, name)))
                {
                    while (File.Exists(Path.Combine(import_path, name + " " + ++i)) ||
                           Directory.Exists(Path.Combine(import_path, name + " " + i)))
                    {
                        ;
                    }
                }
                if (i != 0)
                {
                    name += " " + i;
                }

                Resource.Import(path, Path.Combine(import_path, name));
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not import [" + path + "].",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        private void Import(bool useOffset)
        {
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = System.IO.File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            var key = useOffset ? table.Rows[i][0].ToString() : table.Rows[i][1].ToString();

                            var value = string.Concat(table.Rows[i][2].ToString(), "\t", table.Rows[i][3].ToString(), "\t", table.Rows[i][4].ToString());

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var subtitle in _subtitles)
                {
                    var key = useOffset ? subtitle.Offset.ToString() : subtitle.Text;

                    if (!string.IsNullOrEmpty(key) && strings.ContainsKey(key))
                    {
                        var values = strings[key].Split('\t');
                        subtitle.Translation = values[0];
                        subtitle.Width       = float.Parse(values[1]);
                        subtitle.Height      = float.Parse(values[2]);
                    }
                }

                SubtitleGridView.Invalidate();
                UpdateLabel();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        private void Import(bool useOrder)
        {
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = System.IO.File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            string key;
                            string value;
                            if (useOrder)
                            {
                                key   = string.Concat(table.Rows[i][0].ToString(), "|", table.Rows[i][1].ToString());
                                value = table.Rows[i][3].ToString();
                            }
                            else
                            {
                                key   = table.Rows[i][2].ToString();
                                value = table.Rows[i][3].ToString();
                            }

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var column in _data.Columns)
                {
                    column.SetUniqueValues(strings, useOrder);
                }

                SubtitleGridView.Invalidate();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #5
0
        private void menu_import_file_Click(object sender, EventArgs e)
        {
            DialogResult result = ImportFileDialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string filePath = ImportFileDialog.FileName;

                FileCorruptorProgram.LoadExternalFile(filePath);
                UpdateTargetFilesListBox();

                LoadedFile currentSourceFile = FileCorruptorProgram.GetCurrentSourceFile();
                HexBoxManager.SetHexBoxFile(SOURCE_HEXBOX_ID, ref currentSourceFile);
            }
        }
        private void btnImportPo_Click(object sender, EventArgs e)
        {
            ImportFileDialog.Filter   = "Archivos Po|*.po";
            ImportFileDialog.FileName = string.Concat(Path.GetFileNameWithoutExtension(_file.Path), ".po");
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            _file.ImportPo(ImportFileDialog.FileName, false);

            _selectedSubtitle = null;
            SubtitleGridView.Invalidate();
            DisplaySubtitle(_selectedSubtitleIndex);
            UpdateLabel();
        }
Пример #7
0
        private void ImportTextureMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (ImportFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                LoadedResource.Texture = new Bitmap(ImportFileDialog.FileName);

                Story.Item = new State(LoadedResource);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not import texture.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private bool AddFilesToProject(Project p)
        {
            var fileFilter = p.CompatibleFilesFilter;

            ImportFileDialog.Filter = fileFilter;

            var result = ImportFileDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                Enabled        = false;

                foreach (var fileName in ImportFileDialog.FileNames)
                {
#if !DEBUG
                    try
                    {
#endif
                    p.SetFile(fileName);
#if !DEBUG
                }
                catch (Exception e)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show($"Error al abrir el fichero {fileName}.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Cursor.Current = Cursors.WaitCursor;
                }
#endif
                }
                Cursor.Current = Cursors.Default;
                Enabled        = true;
            }

            return(p.Files.Count > 0);
        }
Пример #9
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            try
            {
                ImportFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
                if (ImportFileDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                using (var file = File.OpenText(ImportFileDialog.FileName))
                {
                    GroupsCount      = 0;
                    ExecutionResults = new Dictionary <string, List <PointD>[]>();
                    ResultsListBox.Items.Clear();
                    ArgumentComboBox.Items.Clear();
                    ArgumentComboBox.Items.Add("Input variable");
                    ArgumentComboBox.SelectedIndex = 0;

                    int    accumulated = 0;
                    string legend      = "";
                    var    legends     = file.ReadLine().Split('\t');

                    foreach (var l in legends)
                    {
                        if (legend == l)
                        {
                            accumulated++;
                        }
                        else if (legend != "")
                        {
                            var array = new List <PointD> [accumulated];
                            for (int i = 0; i < array.Length; i++)
                            {
                                array[i] = new List <PointD>();
                            }
                            ExecutionResults.Add(legend, array);
                            ResultsListBox.Items.Add(legend);
                            ArgumentComboBox.Items.Add(legend);

                            if (accumulated > GroupsCount)
                            {
                                GroupsCount = accumulated;
                            }
                            legend      = l;
                            accumulated = 1;
                        }
                        else
                        {
                            legend      = l;
                            accumulated = 1;
                        }
                    }

                    ExecutionNames = new string[GroupsCount];

                    var groups = file.ReadLine().Split('\t');

                    NameTextBox.Text = groups[0];
                    for (int i = 2; i < GroupsCount + 2; i++)
                    {
                        ExecutionNames[i - 2] = groups[i];
                    }

                    ExecutionLowerBound  = decimal.MaxValue;
                    ExecutionHigherBound = decimal.MinValue;
                    int count = 0;
                    while (!file.EndOfStream)
                    {
                        count++;
                        var values   = file.ReadLine().Split('\t');
                        var argument = decimal.Parse(values[0]);

                        if (argument < ExecutionLowerBound)
                        {
                            ExecutionLowerBound = argument;
                        }
                        if (argument > ExecutionHigherBound)
                        {
                            ExecutionHigherBound = argument;
                        }

                        int i = 0;
                        foreach (var l in ExecutionResults)
                        {
                            for (int j = 0; j < GroupsCount; j++)
                            {
                                int     ind = 2 + i * (GroupsCount + 1);
                                decimal value;
                                if (decimal.TryParse(values[ind], out value))
                                {
                                    l.Value[j].Add(new PointD((double)argument, (double)value));
                                }
                            }
                            i++;
                        }
                    }

                    LowerNumeric.Value  = ExecutionLowerBound;
                    HigherNumeric.Value = ExecutionHigherBound;
                    StepNumeric.Value   = ExecutionStep = (ExecutionHigherBound - ExecutionLowerBound) / (count - 1);

                    BuildGraph();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not import results.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Import(bool useOffset)
        {
            ImportFileDialog.Filter   = "Archivos Excel|*.xlsx";
            ImportFileDialog.FileName = string.Concat(Path.GetFileNameWithoutExtension(_file.Path), ".xlsx");
            var result = ImportFileDialog.ShowDialog(this);

            if (result != DialogResult.OK)
            {
                return;
            }

            var strings = new Dictionary <string, string>();

            try
            {
                using (var stream = File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                {
                    // Auto-detect format, supports:
                    //  - Binary Excel files (2.0-2003 format; *.xls)
                    //  - OpenXml Excel files (2007 format; *.xlsx)
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        var content = reader.AsDataSet();

                        var table = content.Tables[0];

                        for (var i = 0; i < table.Rows.Count; i++)
                        {
                            string key;
                            string value;
                            if (useOffset)
                            {
                                key   = table.Rows[i][0].ToString();
                                value = table.Rows[i][2].ToString();
                            }
                            else
                            {
                                key   = table.Rows[i][1].ToString();
                                value = table.Rows[i][2].ToString();
                            }

                            if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                            {
                                strings.Add(key, value);
                            }
                        }
                    }
                }

                foreach (var subtitle in _subtitles)
                {
                    var key = useOffset ? subtitle.Offset.ToString() : subtitle.Text;

                    if (!string.IsNullOrEmpty(key) && strings.ContainsKey(key))
                    {
                        subtitle.Translation = strings[key];
                    }
                }

                _selectedSubtitle = null;
                SubtitleGridView.Invalidate();
                DisplaySubtitle(_selectedSubtitleIndex);
                UpdateLabel();
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #11
0
        private void ImportExcel(bool complete)
        {
            if (_openProject == null)
            {
                return;
            }

            ImportFileDialog.Filter = "Archivos Excel|*.xls;*.xlsx";

            var result = ImportFileDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                var strings = new Dictionary <string, string>();
                try
                {
                    using (var stream = File.Open(ImportFileDialog.FileName, FileMode.Open, FileAccess.Read))
                    {
                        // Auto-detect format, supports:
                        //  - Binary Excel files (2.0-2003 format; *.xls)
                        //  - OpenXml Excel files (2007 format; *.xlsx)
                        using (var reader = ExcelReaderFactory.CreateReader(stream))
                        {
                            var content = reader.AsDataSet();

                            var table = content.Tables[0];

                            for (int i = 0; i < table.Rows.Count; i++)
                            {
                                string key;
                                string value;
                                if (!complete)
                                {
                                    key   = table.Rows[i][0].ToString();
                                    value = table.Rows[i][1].ToString();
                                }
                                else
                                {
                                    key   = string.Concat(table.Rows[i][0].ToString(), "|", table.Rows[i][1].ToString(), "|", table.Rows[i][2].ToString(), "|", table.Rows[i][3].ToString());
                                    value = table.Rows[i][4].ToString();
                                }

                                if (!string.IsNullOrEmpty(key) && !strings.ContainsKey(key))
                                {
                                    strings.Add(key, value);
                                }
                            }
                        }
                    }

                    var files = _openProject.Files.ToDictionary(file => file.Id, file => Path.GetFileName(file.Path));
                    foreach (var tfString in _openProject.Strings)
                    {
                        string key;
                        if (!complete)
                        {
                            key = tfString.Original;
                        }
                        else
                        {
                            key = files.ContainsKey(tfString.FileId) ? string.Concat(files[tfString.FileId], "|", tfString.Section, "|", tfString.Offset, "|", tfString.Original) : string.Empty;
                        }

                        if (!string.IsNullOrEmpty(key))
                        {
                            if (strings.ContainsKey(key))
                            {
                                tfString.Translation = strings[key];
                            }
                        }
                    }

                    StringsDataGrid.Rows.Clear();
                    LoadDataGrid();
                }
                catch (Exception e)
                {
                    MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #12
0
        private void ImportTF(bool complete)
        {
            if (_openProject == null)
            {
                return;
            }

            ImportFileDialog.Filter = "Traducciones|" + GetOpenProjectFilesFilter();

            var result = ImportFileDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                var strings = new Dictionary <string, string>();

                Project project = null;
#if !DEBUG
                try
                {
#endif
                project = ProjectFactory.GetProject(ImportFileDialog.FileName);

                project.LoadFiles();

                project.LoadStrings();

                var files = project.Files.ToDictionary(file => file.Id, file => Path.GetFileName(file.Path));

                foreach (var tfString in project.Strings)
                {
                    string key;
                    if (!complete)
                    {
                        key = tfString.Original;
                    }
                    else
                    {
                        key = files.ContainsKey(tfString.FileId) ? string.Concat(files[tfString.FileId], "|", tfString.Section, "|", tfString.Offset, "|", tfString.Original) : string.Empty;
                    }

                    var value = tfString.Translation;

                    if (!string.IsNullOrEmpty(key))
                    {
                        if (!strings.ContainsKey(key))
                        {
                            strings.Add(key, value);
                        }
                    }
                }

                project.Close();
#if !DEBUG
            }
            catch (Exception e)
            {
                MessageBox.Show($"No se ha podido abrir el fichero.\r\n{e.GetType()}: {e.Message}", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);

                project?.Close();

                return;
            }
#endif

                var files2 = _openProject.Files.ToDictionary(file => file.Id, file => Path.GetFileName(file.Path));

                foreach (var tfString in _openProject.Strings)
                {
                    string key;
                    if (!complete)
                    {
                        key = tfString.Original;
                    }
                    else
                    {
                        key = files2.ContainsKey(tfString.FileId) ? string.Concat(files2[tfString.FileId], "|", tfString.Section, "|", tfString.Offset, "|", tfString.Original) : string.Empty;
                    }

                    if (!string.IsNullOrEmpty(key))
                    {
                        if (strings.ContainsKey(key))
                        {
                            tfString.Translation = strings[key];
                        }
                    }
                }

                StringsDataGrid.Rows.Clear();
                LoadDataGrid();
            }
        }
Пример #13
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            Table table = (Table)ImportTableComboBox.SelectedItem;

            if ((object)table != null)
            {
                ImportFileDialog.FileName = table.Name;
            }

            DialogResult result = ImportFileDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string fileName = Path.GetFileName(ImportFileDialog.FileName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            Table  matchingTable            = DBSchema.Tables[fileNameWithoutExtension];

            // Each of the import operations require slightly different wording
            Dictionary <object, string> importPhraseLookup = new Dictionary <object, string>()
            {
                { InsertButton, "insert data into" },
                { UpdateButton, "update" },
                { DeleteButton, "delete data from" }
            };

            if (!importPhraseLookup.TryGetValue(sender, out string importPhrase))
            {
                importPhrase = "import data into";
            }

            // Run sanity checks to make sure the user didn't make a mistake
            if ((object)table != null && (object)matchingTable != null && !ReferenceEquals(table, matchingTable))
            {
                DialogResult matchResult = MessageBox.Show($"File name matches another table in the database. Would you like to {importPhrase} the {matchingTable.Name} table instead?", "Matching table detected", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (matchResult == DialogResult.Cancel)
                {
                    return;
                }

                if (matchResult == DialogResult.Yes)
                {
                    ImportTableComboBox.SelectedItem = table = matchingTable;
                }
            }
            else if ((object)table != null)
            {
                DialogResult confirmResult = MessageBox.Show($"You are about to {importPhrase} the {table.Name} table. Are you sure you would like to proceed?", "Confirm import", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (confirmResult == DialogResult.No)
                {
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please select a table to import to.");
                return;
            }

            // Disabling the tab control makes it so the user cannot interact with any
            // controls while the import is executing, but running in a separate thread
            // does allow the user to move the window around while the import executes
            Cursor cursor = Cursor;

            BeginImport();

            Thread t = new Thread(() =>
            {
                try { DoImport(); }
                finally { EndImport(); }
            });

            t.IsBackground = true;
            t.Start();

            void BeginImport()
            {
                if (InvokeRequired)
                {
                    Invoke(new Action(BeginImport));
                    return;
                }

                MainTabControl.Enabled = false;
                Cursor = Cursors.WaitCursor;
                ImportProgressBar.Value = 0;
            }

            void DoImport()
            {
                using (BulkDataOperationBase importer = GetImporter(sender))
                {
                    OpenBothConnectionsAndExecute(() => ImportSelectionFromFile(importer, table));
                }
            }

            void EndImport()
            {
                if (InvokeRequired)
                {
                    Invoke(new Action(EndImport));
                    return;
                }

                MainTabControl.Enabled = true;
                Cursor = cursor;
                ImportProgressBar.Value = 100;
                MessageBox.Show($"Completed import from {fileName} to the {table.Name} table.");
            }
        }
Пример #14
0
        private static ResourceItem CopyFile(ResourceFolder parent, FileOptionHelp.FileData filePath, ref ImportResourceResult importResult, List <FileOptionHelp.FileData> dealDithFiles, IProgressMonitor monitor)
        {
            ResourceItem result;

            try
            {
                if (importResult.Token.IsCancellationRequested)
                {
                    result = null;
                }
                else
                {
                    bool flag = false;
                    if (null != importResult.FileTypeSuffix)
                    {
                        flag = true;
                        if (importResult.FileTypeSuffix.Contains(filePath.FilePath.Extension))
                        {
                            flag = false;
                        }
                    }
                    flag |= filePath.FilePath.Extension.Equals(".ccs", StringComparison.OrdinalIgnoreCase);
                    if (flag)
                    {
                        monitor.Step(1);
                        result = null;
                    }
                    else if (dealDithFiles.Contains(filePath))
                    {
                        result = null;
                    }
                    else
                    {
                        List <string> list = FileOptionHelp.ProcessPairResources(filePath.FilePath);
                        if (list != null)
                        {
                            filePath.CanRename = false;
                        }
                        FilePath filePath2 = parent.BaseDirectory.Combine(new string[]
                        {
                            filePath.Name
                        });
                        DialogResult dialogRes = new DialogResult();
                        if (!FileOptionHelp.VerifyPath(filePath2))
                        {
                            monitor.Step(1);
                            monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, filePath.FilePath), null);
                            result = null;
                        }
                        else if (filePath.FilePath.IsChildPathOf(parent.BaseDirectory))
                        {
                            if (!FileOptionHelp.VerifyPath(filePath.FilePath))
                            {
                                monitor.Step(1);
                                monitor.ReportError(string.Format(LanguageInfo.MessageBox199_PathContainsChinese, filePath.FilePath), null);
                                result = null;
                            }
                            else
                            {
                                ResourceItem resourceItem  = null;
                                ResourceItem resourceItem2 = Services.ProjectOperations.AddResourceItem(parent, filePath.FilePath, monitor, out resourceItem);
                                if (resourceItem != null)
                                {
                                    if (resourceItem.Parent != parent)
                                    {
                                        importResult.AddResourcePanelItems.Add(resourceItem.Parent);
                                    }
                                    else
                                    {
                                        importResult.AddResourcePanelItems.Add(resourceItem);
                                    }
                                }
                                File.SetAttributes(filePath.FilePath, FileAttributes.Normal);
                                result = resourceItem2;
                            }
                        }
                        else
                        {
                            if (File.Exists(filePath2))
                            {
                                if (!importResult.DialogResult.IsChangedAll)
                                {
                                    if (FileOptionHelp.IsMainThread())
                                    {
                                        ImportFileDialog importFileDialog = new ImportFileDialog(Services.MainWindow, filePath.CanRename);
                                        importFileDialog.RefreshMessage(filePath.Name);
                                        dialogRes = importFileDialog.ShowRun();
                                    }
                                    else
                                    {
                                        AutoResetEvent autoReset = new AutoResetEvent(false);
                                        GLib.Timeout.Add(0u, delegate
                                        {
                                            ImportFileDialog importFileDialog2 = new ImportFileDialog(Services.MainWindow, filePath.CanRename);
                                            importFileDialog2.RefreshMessage(filePath.Name);
                                            dialogRes = importFileDialog2.ShowRun();
                                            autoReset.Set();
                                            return(false);
                                        });
                                        autoReset.WaitOne();
                                    }
                                    importResult.DialogResult = dialogRes;
                                }
                                switch (importResult.DialogResult.ButtonResult)
                                {
                                case EImportFileButtonResult.KeepBoth:
                                    if (filePath.CanRename)
                                    {
                                        filePath2 = FileOptionHelp.RenameFile(filePath2);
                                    }
                                    else
                                    {
                                        monitor.ReportWarning(string.Format(LanguageInfo.MessageBox200_CannotRename, filePath.FilePath));
                                    }
                                    break;

                                case EImportFileButtonResult.Skip:
                                    result = null;
                                    return(result);
                                }
                            }
                            if (list != null)
                            {
                                string text = FileOptionHelp.CheckFiles(list);
                                if (!string.IsNullOrWhiteSpace(text))
                                {
                                    monitor.Step(1);
                                    string message = string.Format(LanguageInfo.MessageBox195_NoMatchPng, filePath.FilePath, text);
                                    monitor.ReportWarning(message);
                                    result = null;
                                    return(result);
                                }
                                foreach (FilePath current in list)
                                {
                                    FilePath filePath3 = current.ToRelative(filePath.FilePath.ParentDirectory).ToAbsolute(parent.BaseDirectory);
                                    string   path      = filePath3.ParentDirectory;
                                    if (!Directory.Exists(path))
                                    {
                                        Directory.CreateDirectory(path);
                                    }
                                    FileService.CopyFile(current, filePath3);
                                    File.SetAttributes(filePath3, FileAttributes.Normal);
                                    dealDithFiles.Add(new FileOptionHelp.FileData(current));
                                }
                            }
                            FileService.CopyFile(filePath.FilePath, filePath2);
                            File.SetAttributes(filePath2, FileAttributes.Normal);
                            ResourceItem resourceItem3 = Services.ProjectOperations.AddResourceItem(parent, filePath2, monitor);
                            if (resourceItem3 is Project && importResult.DialogResult.ButtonResult == EImportFileButtonResult.Replace)
                            {
                                ((Project)resourceItem3).Reload(monitor);
                            }
                            result = resourceItem3;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                monitor.Step(1);
                monitor.ReportError(string.Format(LanguageInfo.Output_ImportFailed, filePath.FilePath), exception);
                result = null;
            }
            return(result);
        }
Пример #15
0
        private void ImportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ImportFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    FileStream TXTFileStream = File.Open(ImportFileDialog.FileName, FileMode.Open);
                    String     TXTLineBuffer;
                    int        ImportedEntries = 0;
                    int        IgnoredEntries  = 0;
                    Log("SATEditor : Starting TXT Importer...");

                    using (StreamReader TXTFile = new StreamReader(TXTFileStream))
                    {
                        Log("TXT Importer : Importing all entries to the screen from " + ImportFileDialog.FileName);

                        while ((TXTLineBuffer = TXTFile.ReadLine()) != null)
                        {
                            if (!TXTLineBuffer.StartsWith("#")) // If it's not a comment
                            {
                                char[]   charsToTrim = { '\t', ' ' };
                                String[] Parts       = TXTLineBuffer.Split(charsToTrim, StringSplitOptions.RemoveEmptyEntries);

                                if (Parts.Length >= 6)
                                {
                                    try                // string -> int -> string to check errors beforehand
                                    {
                                        int FNGtempID     = int.Parse(Parts[0]);
                                        int FNGtempOffset = Convert.ToInt32(Parts[1], 16);
                                        int FNGtempRed    = int.Parse(Parts[2]);
                                        int FNGtempGreen  = int.Parse(Parts[3]);
                                        int FNGtempBlue   = int.Parse(Parts[4]);
                                        int FNGtempAlpha  = int.Parse(Parts[5]);
                                        // Hex values in txt are ignored, we will recreate them below with imported values

                                        if ((FNGtempBlue >= 0 && FNGtempBlue <= 255) &&
                                            (FNGtempGreen >= 0 && FNGtempGreen <= 255) &&
                                            (FNGtempRed >= 0 && FNGtempRed <= 255) &&
                                            (FNGtempAlpha >= 0 && FNGtempAlpha <= 255))
                                        {
                                            var FNGItem = new ListViewItem();
                                            FNGItem.Text = FNGtempID.ToString();
                                            FNGItem.SubItems.Add(FNGtempOffset.ToString("X8")); // offset in hex
                                            FNGItem.SubItems.Add(FNGtempRed.ToString());        // red
                                            FNGItem.SubItems.Add(FNGtempGreen.ToString());      // green
                                            FNGItem.SubItems.Add(FNGtempBlue.ToString());       // blue
                                            FNGItem.SubItems.Add(FNGtempAlpha.ToString());      // alpha

                                            // Comments
                                            String Comments = "";
                                            for (int i = 6; i < Parts.Length; i++)
                                            {
                                                Comments += Parts[i] + " ";
                                            }
                                            FNGItem.SubItems.Add(Comments);

                                            // Set item color
                                            FNGItem.BackColor = Color.FromArgb(FNGtempAlpha, FNGtempRed, FNGtempGreen, FNGtempBlue);
                                            float Brightness = FNGItem.BackColor.GetBrightness();
                                            // Make text always readable
                                            if (Brightness > 0.5)
                                            {
                                                FNGItem.ForeColor = Color.Black;
                                            }
                                            else
                                            {
                                                FNGItem.ForeColor = Color.White;
                                            }

                                            // Replace imported item with the old one (if offset strings match)
                                            if (SATEditorList.Items[FNGtempID - 1].SubItems[1].Text == Parts[1])
                                            {
                                                SATEditorList.Items.RemoveAt(FNGtempID - 1);
                                                SATEditorList.Items.Insert(FNGtempID - 1, FNGItem);
                                                ImportedEntries++;
                                            }
                                            else
                                            {
                                                IgnoredEntries++;
                                            }
                                        }
                                        else
                                        {
                                            IgnoredEntries++;
                                        }
                                    }
                                    catch (Exception) // If there is any error, just ingore the line
                                    {
                                        IgnoredEntries++;
                                        continue;
                                    }
                                }
                            }
                        }
                        String Status = "Imported" + " " + ImportedEntries + " " + "entries.";
                        if (IgnoredEntries > 0)
                        {
                            Status += "\n" + "Ignored" + " " + IgnoredEntries + " " + "entries due to some formatting errors in selected text file.";
                        }

                        if (ImportedEntries > 0)
                        {
                            FNGChanged = true;
                        }

                        MessageBox.Show(Status, "SATEditor", MessageBoxButtons.OK);
                        Log("TXT Importer: Imported" + " " + ImportedEntries + " " + "entries from" + " " + ImportFileDialog.FileName);
                        Log("TXT Importer: Ignored" + " " + IgnoredEntries + " " + "entries.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Values could not be imported.", "SATEditor", MessageBoxButtons.OK);
                    Log("TXT Importer : Values could not be imported." + " " + "Exception:" + ex.ToString());
                }
            }
        }
Пример #16
0
 public ImportFileViewModel()
 {
     mDialog = new ImportFileDialog(this);
 }
Пример #17
0
 private void btAutomataImport_Click(object sender, EventArgs e)
 {
     CurrentTypeImport = ImportType.automata_txt;
     ConfigureFileImportDialog("txt files (*.txt)|*.txt");
     ImportFileDialog.ShowDialog();
 }
Пример #18
0
 private void btWordsImport_Click(object sender, EventArgs e)
 {
     CurrentTypeImport = ImportType.words_in;
     ConfigureFileImportDialog("in files (*.in)|*.in");
     ImportFileDialog.ShowDialog();
 }