コード例 #1
0
        private void LoadFtAs()
        {
            FTAListView.Items.Clear();
            if (_remoteApp.FileTypeAssociations != null)
            {
                foreach (RemoteAppLib.New.FileTypeAssociation fta in _remoteApp.FileTypeAssociations)
                {
                    var    FTitem = new ListViewItem(fta.Extension);
                    string ftaStatus;
                    if (LocalFtaModule.DoesFtaExist(fta.Extension))
                    {
                        // FTA exists - created by another app
                        ftaStatus = "Existing";
                        if (LocalFtaModule.IsFtaMine(fta.Extension))
                        {
                            // FTA exists - created by RemoteApp Tool
                            ftaStatus = "Yes";
                        }
                    }
                    else
                    {
                        // FTA does not exist
                        ftaStatus = "No";
                    }

                    FTitem.SubItems.Add(fta.IconPath);
                    FTitem.SubItems.Add(fta.IconIndex);
                    FTitem.SubItems.Add(ftaStatus);
                    FTAListView.Items.Add(FTitem);
                }
            }

            CheckSelection();
        }
コード例 #2
0
        private void SetAssociationButton_Click(object sender, EventArgs e) // NEED TO SORT OUT EVERYTHING IN THIS SUB!!!
        {
            var fta = new RemoteAppLib.New.FileTypeAssociation
            {
                Extension = FTAListView.SelectedItems[0].SubItems[0].Text,
                IconPath  = FTAListView.SelectedItems[0].SubItems[1].Text,
                IconIndex = FTAListView.SelectedItems[0].SubItems[2].Text
            };

            if (LocalFtaModule.DoesFtaExist(fta.Extension))
            {
                DialogResult MsgBoxResult;
                // An existing association was found
                if (!LocalFtaModule.IsFtaMine(fta.Extension))
                {
                    // FTA found and belongs to another application (replace?)
                    MsgBoxResult = MessageBox.Show("An association already exists on the local computer for filetype. Would you like to replace it?" + Environment.NewLine + Environment.NewLine + "Warning: This association was created by another application. Replacing it can cause problems. If the existing association is working, there is no need to replace it.", "File Type Association", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                    if (MsgBoxResult == DialogResult.Yes)
                    {
                        LocalFtaModule.CreateFta(fta, _remoteApp.Path, _remoteApp.Name, true);
                    }
                }
                else
                {
                    // FTA found and belongs to RemoteApp Tool (remove)
                    MsgBoxResult = MessageBox.Show("Are you sure you want to remove this file type association on the local computer?", "File Type Association", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                    if (MsgBoxResult == DialogResult.Yes)
                    {
                        LocalFtaModule.DeleteFta(fta.Extension);
                    }
                }
            }
            // FTA not found (create)
            else if (LocalFtaModule.CreateFta(fta, _remoteApp.Path, _remoteApp.Name))
            {
                MessageBox.Show("File type association created for " + fta.Extension + ".", "File Type Association", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("File type association not created. There was an error.", "File Type Association", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            LoadFtAs();
        }