Exemplo n.º 1
0
        public bool Edit()
        {
            List <IFileData> selectedFiles = GetSelectedFiles();

            if (selectedFiles.Count > 0)
            {
                IFileData           file = selectedFiles.First();
                FileDetailsEditForm form = new FileDetailsEditForm();
                form.Initialize(DataSourceAdapter, file);
                form.StartPosition = FormStartPosition.CenterParent;

                if (form.ShowDialog(this) == DialogResult.OK && form.SourcePort != null && !file.IsUrl)
                {
                    file.SourcePortID = form.SourcePort.SourcePortID;
                    file.Description  = form.Description;
                    DataSourceAdapter.UpdateFile(file);
                    return(true);
                }
                else if (form.SourcePort == null)
                {
                    MessageBox.Show(this, "A source port must be selected.", "Error", MessageBoxButtons.OK);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public bool New()
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return(false);
            }
            FileDetailsEditForm detailsForm = new FileDetailsEditForm();

            detailsForm.Initialize(this.DataSourceAdapter);
            detailsForm.StartPosition = FormStartPosition.CenterParent;
            if ((detailsForm.ShowDialog(this) == DialogResult.OK) && (detailsForm.SourcePort != null))
            {
                this.GameFile = this.DataSourceAdapter.GetGameFile(this.GameFile.FileName);
                string[] fileNames = dialog.FileNames;
                for (int i = 0; i < fileNames.Length; i++)
                {
                    FileInfo       fi = new FileInfo(fileNames[i]);
                    FileDataSource ds = this.CreateNewFileDataSource(detailsForm, fi);
                    fi.CopyTo(Path.Combine(this.DataDirectory.GetFullPath(), ds.FileName));
                    this.DataSourceAdapter.InsertFile(ds);
                }
            }
            else if (detailsForm.SourcePort == null)
            {
                this.ShowSourcePortError();
            }
            return(true);
        }
Exemplo n.º 3
0
        public static List <IFileData> CreateFileAssociation(IWin32Window parent, IDataSourceAdapter adapter, LauncherPath directory, FileType type, IGameFile gameFile,
                                                             ISourcePortData sourcePort, bool multiSelect = false)
        {
            List <IFileData> fileDataList = new List <IFileData>();
            OpenFileDialog   dialog       = new OpenFileDialog();

            dialog.Multiselect = multiSelect;

            if (dialog.ShowDialog(parent) == DialogResult.OK)
            {
                bool isMultiImport = dialog.FileNames.Length > 1;

                FileDetailsEditForm detailsForm = new FileDetailsEditForm();
                detailsForm.Initialize(adapter);
                detailsForm.StartPosition = FormStartPosition.CenterParent;
                detailsForm.ShowDescription(!isMultiImport);
                if (sourcePort != null)
                {
                    detailsForm.SourcePort = sourcePort;
                }
                if (!isMultiImport)
                {
                    detailsForm.Description = Path.GetFileName(dialog.FileNames[0]);
                }

                if (detailsForm.ShowDialog(parent) == DialogResult.OK && detailsForm.SourcePort != null)
                {
                    foreach (string file in dialog.FileNames)
                    {
                        FileInfo  fi       = new FileInfo(file);
                        IFileData fileData = CreateNewFileDataSource(detailsForm, fi, type, gameFile);
                        if (isMultiImport)
                        {
                            fileData.Description = Path.GetFileName(file);
                        }

                        fi.CopyTo(Path.Combine(directory.GetFullPath(), fileData.FileName));

                        adapter.InsertFile(fileData);
                        var fileSearch = adapter.GetFiles(gameFile, type).FirstOrDefault(x => x.FileName == fileData.FileName);
                        if (fileSearch != null)
                        {
                            fileData = fileSearch;
                        }
                        fileDataList.Add(fileData);
                    }
                }
                else if (detailsForm.SourcePort == null)
                {
                    MessageBox.Show(parent, "A source port must be selected.", "Error", MessageBoxButtons.OK);
                }
            }

            return(fileDataList);
        }