示例#1
0
 public void Dispose()
 {
     openFileDialog?.Dispose();
     saveFileDialog?.Dispose();
     exportFileDialog?.Dispose();
     importFileDialog?.Dispose();
 }
示例#2
0
        public static string ShowSaveProjectDialog <T>(T project) where T : BaseProject, new()
        {
            if (project == null)
            {
                return(null);
            }

            string         projectTypeName = GetTypeName <T>();
            SaveFileDialog saveFileDialog  = new SaveFileDialog();

            saveFileDialog.Filter = string.Format(
                "{0} (*.{1})|*.{2}|All files (*.*)|*.*",
                projectTypeName,
                project.ProjectFormat?.ToUpper() ?? string.Empty,
                project.ProjectFormat ?? string.Empty);

            saveFileDialog.Title    = "Save " + projectTypeName;
            saveFileDialog.FileName = project.ProjectName ?? string.Empty;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string targetPath = saveFileDialog.FileName;

                if (SaveProject(saveFileDialog.FileName, project))
                {
                    saveFileDialog?.Dispose();
                    return(targetPath);
                }
                else
                {
                    MessageBox.Show("Invalid project file.", "Error", MessageBoxButtons.OK);
                }
            }

            saveFileDialog?.Dispose();

            return(null);
        }
示例#3
0
        /// <summary>
        /// Function to retrieve a single file name.
        /// </summary>
        /// <returns>The selected file path, or <b>null</b> if cancelled.</returns>
        public virtual string GetFilename()
        {
            SaveFileDialog dialog = null;

            try
            {
                dialog = GetDialog();

                return(dialog.ShowDialog(GetParentForm()) == DialogResult.Cancel ? null : dialog.FileName);
            }
            finally
            {
                dialog?.Dispose();
            }
        }
示例#4
0
文件: EndPage.cs 项目: Adel-dz/Hub
        //handlers
        private void Save_Click(object sender , EventArgs e)
        {
            SaveFileDialog sfDlg = null;

            try
            {
                sfDlg = new SaveFileDialog();
                sfDlg.Filter = "Fichiers texte|*.txt|Tous les fichiers|*.*";

                if (sfDlg.ShowDialog() == DialogResult.OK)
                    File.WriteAllText(sfDlg.FileName , m_tbBadRows.Text);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message , null , MessageBoxButtons.OK , MessageBoxIcon.Error);
            }
            finally
            {
                sfDlg?.Dispose();
            }
        }
        /**************************************************************************/

        private void CallbackSaveOverviewCsvReport(object sender, EventArgs e)
        {
            SaveFileDialog Dialog = new SaveFileDialog();

            Dialog.Filter           = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
            Dialog.FilterIndex      = 2;
            Dialog.RestoreDirectory = true;
            Dialog.DefaultExt       = "csv";
            Dialog.AddExtension     = true;
            Dialog.FileName         = "Macroscope-Overview.csv";

            this.Enabled = false;

            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                string Path = Dialog.FileName;
                MacroscopeCsvOverviewReport CsvReport = new MacroscopeCsvOverviewReport();

                try
                {
                    CsvReport.WriteCsv(this.JobMaster, Path);
                }
                catch (MacroscopeSaveCsvFileException ex)
                {
                    this.DialogueBoxError("Error saving Overview CSV Report", ex.Message);
                }
                catch (Exception ex)
                {
                    this.DialogueBoxError("Error saving Overview CSV Report", ex.Message);
                }
            }

            if (Dialog != null)
            {
                Dialog.Dispose();
            }

            this.Enabled = true;
        }
示例#6
0
        /// <summary>
        /// Backup current user's settings and problem description into a .uapak file.
        /// Depends on external program "unzip\unzip.exe"
        /// </summary>
        public static void BackupData()
        {
            string path = LocalDirectory.DefaultPath;
            if (!System.IO.Directory.Exists(path)) return;

            string file = @"unzip\unzip.exe";
            file = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), file);
            if (!System.IO.File.Exists(file)) return;

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.FileName = "Problems.uapak";
            sfd.Filter = "UVA Arena Package | *.uapak";
            sfd.DefaultExt = ".uapak";
            sfd.AddExtension = true;
            sfd.CheckPathExists = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(Backup, sfd.FileName);
            }
            sfd.Dispose();
        }
示例#7
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.DefaultExt       = "txt";
            saveFileDialog.Filter           = " RichTextFile |*.rtf|Text file (*.txt)|*.txt|XML file (*.xml)|*.xml|All files (*.*)|*.*";//"Word document(*.doc/*.docx)|*.doc*";//
            saveFileDialog.AddExtension     = true;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.Title            = "Chọn đường dẫn lưu";
            saveFileDialog.InitialDirectory = @"C:/";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                // MessageBox.Show("You selected the file: " + saveFileDialog.FileName);
                if (ckbXemDsXuat.Checked)
                {
                    rtxtNoiDungCauHoi.SaveFile(saveFileDialog.FileName);
                    MessageBox.Show("Xuất file thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    rtxtNoiDungCauHoi.Text = "";
                    foreach (var item in lstDsXuatCauHoi)
                    {
                        showSimpleQuestionInRichTextBox(item);
                    }

                    rtxtNoiDungCauHoi.SaveFile(saveFileDialog.FileName);
                    MessageBox.Show("Xuất file thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Xuất file thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);

                // MessageBox.Show("You hit cancel or closed the dialog.");
            }
            saveFileDialog.Dispose();
            saveFileDialog = null;
        }
示例#8
0
        /// <summary>
        /// 获取保存文件名称
        /// </summary>
        /// <param name="Filter">文件类型</param>
        /// <param name="InitDir">保存的默认目录</param>
        /// <param name="InitFileName">默认文件名称</param>
        /// <returns></returns>
        public static string GetSaveFileName(string Filter, string InitDir, string InitFileName)
        {
            SaveFileDialog saveFileDialog = null;
            string         result;

            try
            {
                saveFileDialog        = new SaveFileDialog();
                saveFileDialog.Filter = Filter;
                if (InitDir != "")
                {
                    saveFileDialog.InitialDirectory = InitDir;
                }
                if (InitFileName != "")
                {
                    saveFileDialog.FileName = InitFileName;
                }
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    result = saveFileDialog.FileName;
                }
                else
                {
                    result = "";
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (saveFileDialog != null)
                {
                    saveFileDialog.Dispose();
                }
            }
            return(result);
        }
示例#9
0
        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            // dialog.InitialDirectory = "C:\\Users\\Administrator\\Desktop";
            dialog.Title            = "保存到";
            dialog.Filter           = " csv文件(*.csv)| *.csv|文本文件(*.txt)| *.txt";
            dialog.RestoreDirectory = true;
            dialog.FilterIndex      = 1;
            DateTime d     = DateTime.Now;
            String   date1 = d.ToShortDateString();
            string   date2 = d.ToShortTimeString();

            date1 = date1.Replace("/", "");
            date1 = date1.Remove(0, 4);
            if (date1.Length == 3)
            {
                date1 = date1.Insert(2, "-0");
            }
            else
            {
                date1 = date1.Insert(2, "-");
            }
            date2 = date2.Replace(":", "");
            date1 = date1 + " " + date2;
            string timename = date1;

            dialog.FileName     = timename + ".csv";
            dialog.AddExtension = false;
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string localFilePath = dialog.FileName.ToString();
                string fileNameExt   = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1);
                string fname         = dialog.FileName;
                System.IO.File.WriteAllText(fname, richTextBox1.Text, Encoding.GetEncoding("gb2312"));
                dialog.Dispose();
            }
            label6.Text = "文件保存完毕";
        }
示例#10
0
        private void save_Click(object sender, EventArgs e)
        {
            SaveFileDialog o = new SaveFileDialog
            {
                AddExtension    = true,
                DefaultExt      = ".png",
                Filter          = FileFilter,
                OverwritePrompt = true
            };

            if (o.ShowDialog() == DialogResult.OK)
            {
                if (o.FilterIndex == 2)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (o.FilterIndex == 1)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Png);
                }
                else if (o.FilterIndex == 3)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                else if (o.FilterIndex == 4)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Tiff);
                }
                else if (o.FilterIndex == 5)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Gif);
                }
                else if (o.FilterIndex == 6)
                {
                    pictureBox1.Image.Save(o.FileName, System.Drawing.Imaging.ImageFormat.Icon);
                }
            }
            o.Dispose();
        }
示例#11
0
        private void buttonSaveAccruals_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();

            ofd.FileName = "Accrual_Definitions.xml";
            ofd.ShowDialog();
            if (ofd.FileName != null && ofd.FileName.Length > 0)
            {
                DataSet  ds_write   = Local.BingoDataSet.Copy();
                String[] save_names = new String[] { AccrualGroup.AccrualGroupTable.TableName
                                                     , AccrualGroup.AccrualGroupTable.AccrualGroupInputCategoryTable.TableName
                                                     , AccrualGroup.AccrualGroupTable.AccrualGroupInputListPickTable.TableName
                                                     , AccrualGroup.AccrualGroupTable.AccrualGroupInputProgramTable.TableName
                                                     , AccrualGroup.AccrualGroupTable.AccrualGroupInputSessionTable.TableName };
                ds_write.EnforceConstraints = false;
                foreach (DataTable dt in ds_write.Tables)
                {
                    bool found = false;
                    foreach (String name in save_names)
                    {
                        if (String.Compare(name, dt.TableName, true) == 0)
                        {
                            found = true; break;
                        }
                    }
                    if (dt.Rows.Count > 0)
                    {
                        xperdex.classes.Log.log(dt.TableName + "Table has some rows...");
                    }
                    if (!found)
                    {
                        dt.Clear();
                    }
                }
                ds_write.WriteXml(ofd.FileName);
            }
            ofd.Dispose();
        }
示例#12
0
        private void SaveXLS_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.Workbook    ObjWorkBook;
            Microsoft.Office.Interop.Excel.Worksheet   ObjWorkSheet;
            //Книга.
            ObjWorkBook = ObjExcel.Workbooks.Add(System.Reflection.Missing.Value);
            //Таблица.
            ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Sheets[1];

            //Значения [y - строка,x - столбец]
            for (int i = 0; i <= ArrData.rowNumber; i++)
            {
                ObjWorkSheet.Cells[i + 1, 1] = ArrData.arrNum[i];
                ObjWorkSheet.Cells[i + 1, 2] = ArrData.arrValue[i];
            }


            string         fileName    = String.Empty;
            SaveFileDialog saveFileXLS = new SaveFileDialog();

            saveFileXLS.Filter           = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            saveFileXLS.FilterIndex      = 2;
            saveFileXLS.RestoreDirectory = true;
            if (saveFileXLS.ShowDialog() == DialogResult.OK)
            {
                fileName = saveFileXLS.FileName;
            }
            else
            {
                return;
            }

            ObjWorkBook.SaveAs(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            ObjWorkBook.Close(false, Type.Missing, Type.Missing);
            ObjExcel.Quit();
            saveFileXLS.Dispose();
        }
示例#13
0
        private void StatusSave()
        {
            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.DefaultExt       = "txt";
                saveFileDialog.Filter           = "Text file (*.txt)|*.txt";
                saveFileDialog.AddExtension     = true;
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.Title            = "Save Status";
                saveFileDialog.FileName         = "status.txt";

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    StreamWriter logFile = new System.IO.StreamWriter(saveFileDialog.FileName);

                    logFile.WriteLine(this.Text);
                    logFile.WriteLine(string.Format("Status Dump [{0}]" + Environment.NewLine, DateTime.Now));

                    for (int i = 0; i < TEXTBOX_MainStatus.Lines.Length; i++)
                    {
                        logFile.WriteLine(TEXTBOX_MainStatus.Lines[i]);
                    }

                    logFile.Close();

                    StatusUpdate("", TextUpdateType.Normal);
                    StatusUpdate(string.Format("File Saved To [{0}]", saveFileDialog.FileName), TextUpdateType.Success);
                }

                saveFileDialog.Dispose();
                saveFileDialog = null;
            }
            catch
            {
                System.Diagnostics.Debug.Assert(false, "Save Status Exception");
            }
        }
示例#14
0
        public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions)
        {
            var fd = new SaveFileDialog();

            fd.Title = title;

            var finalFilename = "";

            if (!string.IsNullOrEmpty(directory))
            {
                finalFilename = GetDirectoryPath(directory);
            }

            if (!string.IsNullOrEmpty(defaultName))
            {
                finalFilename += defaultName;
            }

            fd.FileName = finalFilename;
            if (extensions != null)
            {
                fd.Filter       = GetFilterFromFileExtensionList(extensions);
                fd.FilterIndex  = 1;
                fd.DefaultExt   = extensions[0].Extensions[0];
                fd.AddExtension = true;
            }
            else
            {
                fd.DefaultExt   = string.Empty;
                fd.Filter       = string.Empty;
                fd.AddExtension = false;
            }
            var res      = fd.ShowDialog(new WindowWrapper(GetActiveWindow()));
            var filename = res == DialogResult.OK ? fd.FileName : "";

            fd.Dispose();
            return(filename);
        }
示例#15
0
        void SaveAs()
        {
            TextEditorControl editor = textEditorContent;

            if (editor != null)
            {
                SaveFileDialog dialog = null;
                try
                {
                    dialog             = new SaveFileDialog();
                    dialog.Filter      = SharpPadFileFilter;
                    dialog.FilterIndex = 0;
                    dialog.FileName    = this.SaveFileName;
                    DialogResult result = dialog.ShowDialog();
                    if (DialogResult.OK == result)
                    {
                        string kk = editor.Text;
                        FileHelper.WriteFile(dialog.FileName, editor.Text);
                    }
                }
                catch (System.AccessViolationException accEx)
                {
                    LogHelper.WriteException(accEx);
                }
                catch (System.StackOverflowException flowEx)
                {
                    LogHelper.WriteException(flowEx);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteException(ex);
                }
                finally
                {
                    dialog.Dispose();
                }
            }
        }
示例#16
0
        public Boolean save()
        {
            if (IsNew)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.FileName = safePatch;
                saveFileDialog.Filter   = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";

                DialogResult result = saveFileDialog.ShowDialog(editor);
                saveFileDialog.Dispose();

                if (result == DialogResult.OK)
                {
                    patch     = saveFileDialog.FileName;
                    safePatch = Path.GetFileName(patch);

                    textBox.SaveFile(patch);
                    Modified = false;
                    IsNew    = false;
                }
                else if (result == DialogResult.Cancel)
                {
                    return(false);
                }
            }
            else
            {
                textBox.SaveFile(patch);
                Modified = false;
            }

            editor.save.Enabled    = false;
            editor.saveAll.Enabled = false;

            redoUndoPos = 0;

            return(true);
        }
示例#17
0
        private void Save_Click(object sender, EventArgs e)
        {
            if (gameObjects == null)
            {
                return;
            }

            var lines = GOToOutput(gameObjects, out string extention);

            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Filter           = string.Format("{0} files (*{0})|*{0}", extention),
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                File.WriteAllLines(saveFileDialog.FileName, lines);
            }

            saveFileDialog.Dispose();
        }
示例#18
0
        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.UpdateFromGrid();

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter           = "Command Files (*.xml;*.lst)|*.xml;*.lst|All files (*.*)|*.*";
            dlg.FilterIndex      = 1;
            dlg.RestoreDirectory = true;
            dlg.FileName         = this.currentFile;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.merger.Save(dlg.FileName);
                this.saveCompleted = true;
                this.mergerOrig    = (SplitMergeCmdFile)this.merger.Clone();
                this.mruMenu.AddFile(dlg.FileName);
                this.currentFile = dlg.FileName;
            }

            dlg.Dispose();
            this.UpdateGrid();
        }
示例#19
0
        /// <summary>
        /// METHOD: SaveImage, saves the current image to a specified file path
        /// </summary>
        public void SaveImage()
        {
            // DECLARE a new SaveFileDialog as a new SaveFileDialog
            SaveFileDialog saveFile = new SaveFileDialog();

            // SET the save file filter to the image formats you would like to
            // save the image as
            saveFile.Filter = "Images|*.png;*.bmp;*.jpg";
            // DECLARE a new ImageFormat and instantiate it to
            // ImageFormat.Bmp
            ImageFormat format = ImageFormat.Bmp;

            // IF the saveFile dialog is open
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                // THEN
                // CALL to currImg.Save method, passing in the file name typed in
                // and the desired format as a parameter
                currImg.Save(saveFile.FileName, format);
            }
            // DISPOSE of the SaveFIleDialog
            saveFile.Dispose();
        }
示例#20
0
        private void SaveBut_Click(object sender, EventArgs e)
        {
            SaveFileDialog ofd = new SaveFileDialog();

            ofd.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            ofd.FilterIndex      = 1;
            ofd.InitialDirectory = Application.StartupPath;
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                ShowWait1();
                //deserialize
                string fpth = ofd.FileName;
                mySonyLib.Locator.DeviceSave(fpth, curDev);
                ofd.Dispose();
                curDev = mySonyLib.Locator.DeviceLoad(fpth);
                UpdateLog(LogPath.Text, LogName.Text);
                UpdateDevice();
                UpdateDeviceList();
                SaveBut.Enabled = true;
                HideWait1();
            }
        }
        //PreConditions: Clicked the Save As Tool Item
        //PostConditions: Opens a dialog and saves any data
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Open a save file dialog
            SaveFileDialog sfd = new SaveFileDialog();

            //Lets setup some values
            sfd.CheckFileExists  = false;                              //No need for overwrite check
            sfd.InitialDirectory = "..\\";                             //Sets the location of the opening file
            sfd.RestoreDirectory = true;                               //Go to previously opened location (if there was one)
            sfd.Filter           = "UserParcelViewData (*.dat)|*.dat"; //Only show .dat files

            //Show the dialog and wait for a response
            DialogResult saveResult = sfd.ShowDialog();

            //If the dialog was a success lets save the upv
            if (saveResult == DialogResult.OK)
            {
                SaveUPVToFile(upv, sfd.FileName);
            }

            //Dispose the form
            sfd.Dispose();
        }
示例#22
0
        private void saveFIleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Save the contents of the textboxes to a user specified .txt file
            vWriteStudentsToList();
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter           = "Text files (*.txt)|*.txt";
            sfd.Title            = "Save Text File - Students";
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    System.IO.File.WriteAllLines(sfd.FileName, lstStudents.ToArray());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            sfd.Dispose();
        }
示例#23
0
        public override void Action(object sender, EventArgs e)
        {
            try
            {
                List <Control> controls = cmd.canvas.GetMemento();

                SaveFileDialog saveFD = new SaveFileDialog();
                saveFD.Filter = "JSON (*.json)|*.json|CSV (*.csv)|*.csv|XML (*.xml)|*.xml|YML (*.yml)|*.yml";
                DialogResult res = saveFD.ShowDialog();

                if (res == DialogResult.OK)
                {
                    // TODO: save file
                    IFigureIO f = FigureIO_Selector.GetInstance(saveFD.FileName.Remove(0, saveFD.FileName.LastIndexOf('.') + 1));
                    f.PathToFile = saveFD.FileName;
                    f.Write(controls);
                }
                saveFD.Dispose();

                Form.ActiveForm.Close();
            }
            catch { }
        }
示例#24
0
        private void ExportLogBtn_Click(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog();

            dialog.DefaultExt       = ".log";
            dialog.InitialDirectory = AppDir;
            dialog.AddExtension     = true;
            dialog.Title            = "Choose where to save the log.";
            dialog.Filter           = "Log files (*.log)|*.log";
            Stream myStream;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = dialog.OpenFile()) != null)
                {
                    byte[] to_write = Encoding.UTF8.GetBytes(LogText);
                    myStream.Write(to_write, 0, to_write.Length);
                    myStream.Close();
                    prnt("Log has been saved.");
                }
            }
            dialog.Dispose();
        }
示例#25
0
        private bool SaveAs()
        {
            if (Board == null)
            {
                MessageBox.Show("Nothing to save");
                return(false);
            }
            Board.Paused = true;

            SaveFileDialog d = new SaveFileDialog();

            d.Filter = Board.Filter;
            bool r = false;

            if (d.ShowDialog() == DialogResult.OK)
            {
                WorkingFile = new FileInfo(d.FileName);
                r           = Save();
            }

            d.Dispose();
            return(r);
        }
示例#26
0
        private void m_btnAxisSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog DialogSave = new SaveFileDialog();

            DialogSave.InitialDirectory = InfoObjectFactory.GetInfoObject("Clamp Teach").IniDirPath;
            DialogSave.Filter           = "Ini file (*.ini)|";
            DialogSave.DefaultExt       = "ini";

            if (DialogSave.ShowDialog() == DialogResult.OK)
            {
                if (DialogSave.FileName != "")
                {
                    IniFile iniFile = new IniFile(DialogSave.FileName);

                    /*iniFile.WriteValue("Alignment X", "Position", m_tbxAlignXClamp.Text);
                     * iniFile.WriteValue("Alignment Y", "Position", m_tbxAlignYClamp.Text);
                     * iniFile.WriteValue("Bar1", "Position", m_tbxAlignYClamp.Text);
                     * iniFile.WriteValue("Bar2", "Position", m_tbxAlignYClamp.Text);     */
                }
            }
            DialogSave.Dispose();
            DialogSave = null;
        }
        private void vSaveFile()
        {
            //SaveFileDialog Saves questions and answers to a user specefied location
            vWriteQuestionsToList();
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter           = "Text files (*.txt)|*.txt";
            sfd.Title            = "Save Text File - Question";
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    System.IO.File.WriteAllLines(sfd.FileName, lstQnA.ToArray());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            sfd.Dispose();
        }
示例#28
0
        private void m_btnAxisSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog DialogSave = new SaveFileDialog();

            DialogSave.InitialDirectory = TeachingInfoFactory.GetTeachInfoObject("Clamp Teach").IniDirPath;
            DialogSave.Filter           = "Ini file (*.ini)|";
            DialogSave.DefaultExt       = "ini";

            if (DialogSave.ShowDialog() == DialogResult.OK)
            {
                if (DialogSave.FileName != "")
                {
                    IniFile iniFile = new IniFile(DialogSave.FileName);

                    iniFile.WriteValue("Alignment C1C2", "Position", CC_C1C2_Axis.GetC1C2AxisPosition());
                    iniFile.WriteValue("Alignment SA1SA2", "Position", CC_SA1SA2_Axis.GetSA1SA2AxisPosition());
                    iniFile.WriteValue("Bar1", "Position", CC_Bar_Axis.GetBar1AxisPosition());
                    iniFile.WriteValue("Bar2", "Position", CC_Bar_Axis.GetBar2AxisPosition());
                }
            }
            DialogSave.Dispose();
            DialogSave = null;
        }
示例#29
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (!this.checkBox1.Checked)
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName = Path.GetFileNameWithoutExtension(this.BasePath);
                sfd.DefaultExt = this.comboBox1.SelectedItem.ToString().ToLower();
                sfd.InitialDirectory = Path.GetDirectoryName(this.BasePath);
                sfd.Filter = "JEPGファイル|*.jpg;*.jpeg|PNGファイル|*.png|GIFファイル|*.gif|BMPファイル|*.bmp";
                sfd.Title = "名前を付けて保存";

                if(DialogResult.OK == sfd.ShowDialog())
                {
                    this.pictureBox1.Image.Save(sfd.FileName, (ImageFormat)this.comboBox1.SelectedItem);
                    sfd.Dispose();
                }
            }
            else 
            {
                string path = Path.Combine(Path.GetDirectoryName(this.BasePath), Path.GetFileNameWithoutExtension(this.BasePath)) + "." + this.comboBox1.SelectedItem.ToString().ToLower();
                this.pictureBox1.Image.Save(path, (ImageFormat)this.comboBox1.SelectedItem);
            }
        }
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (!btnBrowse.Enabled)
            {
                return;
            }

            SaveFileDialog _dialog = new SaveFileDialog();

            _dialog.DefaultExt = "scmsiv";
            _dialog.Filter     = "SCMS Database Backup Files (*.scmsiv)|*.scmsiv";
            _dialog.Title      = "Select Output Path";
            _dialog.FileName   = SCMS.ServerConnection.Database.ToUpper() + "_BACKUP_" + VisualBasic.Format(DateTime.Now, "dd_MM_yyyy_HH_mm_ss") + ".scmsiv";
            if (_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (!String.IsNullOrEmpty(_dialog.FileName.RLTrim()))
                {
                    lblPath.Text = _dialog.FileName;
                }
            }
            _dialog.Dispose(); _dialog = null;
            Materia.RefreshAndManageCurrentProcess();
        }
示例#31
0
        private void SaveTo_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter           = "XML Files (*.xml)|*.xml";
                sfd.FilterIndex      = 0;
                sfd.DefaultExt       = "xml";
                sfd.RestoreDirectory = true;

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    File.WriteAllText(sfd.FileName, XMLViewer.Text);
                    MessageBox.Show("File saved");
                }
                Log("New file " + sfd.FileName + " saved!");
                sfd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#32
0
	private void mExternaliseOnClick(object sender, EventArgs e)
	{
		//Externalise dlls
		//Moves dlls from within the exe to the exe directory
		//Similar to the ExternaliseDLLS=Yes dbpro compiler option discussed here
		//http://forum.thegamecreators.com/?m=forum_view&t=129081&b=18
		
		//can't externalise compressed exes
		if (proExe.IsCompressed(contents) == true)
		{
			MessageBox.Show("Exe is already compressed.", "Error!",
				MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}

		//don't externalise .pck files or dbc exes
		if (contents.Items.Count < 2 || contents.Items[1].Text != ListViewStrings.VirtualDat)
		{
			MessageBox.Show("Exe is a .pck or dbc exe", "Error!",
				MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}

		SaveFileDialog sfd = new SaveFileDialog();
		sfd.Title = "Save externalised Exe as";
		sfd.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		if (sfd.ShowDialog() == DialogResult.OK)
		{
			String directory = Path.GetDirectoryName(sfd.FileName);
			ArrayList files = new ArrayList();
			foreach (ListViewFileItem lvi in contents.Items)
			{
				if (lvi.Text.EndsWith(".dll"))
				{
					//save dll in directory
					proExe.ExtractFile(lvi, exeName.Text, directory + Path.DirectorySeparatorChar + lvi.Text);
				}
				else
				{
					//not a dll, add it to list of files to save in exe
					files.Add(lvi);
				}
			}
			proExe.SaveExe(files, sfd.FileName, exeName.Text, true, displaySettings);
		}

		sfd.Dispose();
	}
示例#33
0
	private void mCompressOnClick(object sender, EventArgs e)
	{
		//compress exe
		//decompress loaded exe
		SaveFileDialog sfd = new SaveFileDialog();
		sfd.Title = "Save compressed exe/pck as";
		sfd.Filter = "Exe or Pck Files (*.exe, *.pck)|*.exe;*.pck|All Files (*.*)|*.*";
		OpenFileDialog ofd = new OpenFileDialog();
		ofd.Title = "Select " + ListViewStrings.CompressDll;
		ofd.Filter = ListViewStrings.CompressDll + "|" + ListViewStrings.CompressDll + "|Dll Files (*.dll)|*.dll|All Files (*.*)|*.*";
		//check for compress.dll to ensure exe is not compressed.
		if (proExe.IsCompressed(contents) == true)
		{
			MessageBox.Show("Exe is already compressed.", "Error!",
				MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}
		if (sfd.ShowDialog() == DialogResult.OK)
		{
			//Make sure filenames don't match, this is really just to ensure there is a backup incase compression fails
			if (exeName.Text == sfd.FileName)
			{
				MessageBox.Show("Compressed exe filename and decompressed exe filename must be different.", "Error!",
					MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			if (ofd.ShowDialog() == DialogResult.OK)
			{
				Cursor.Current = Cursors.WaitCursor;
				bool dbPro = false;
				if (exeType.SelectedIndex == exeType.Items.IndexOf("DbPro"))
					dbPro = true;
				proExe.CompressExe(contents.Items, dbPro, displaySettings, exeName.Text, sfd.FileName, ofd.FileName);
				Cursor.Current = Cursors.Default;
			}
		}
		sfd.Dispose();
	}
示例#34
0
	private void mExtractOnClick(object sender, EventArgs ea)
	{
		//extract file
		foreach (ListViewFileItem lvi in contents.SelectedItems)
		{
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Title = "Extract file as";
			sfd.Filter = "All Files (*.*)|*.*";
			//extract file
               sfd.FileName = Path.GetFileName(proExe.DbcRemoveNull(lvi.Text));
			if (sfd.ShowDialog() == DialogResult.OK)
			{
				Cursor.Current = Cursors.WaitCursor;
				proExe.ExtractFile(lvi, exeName.Text, sfd.FileName);
				Cursor.Current = Cursors.Default;
			}
			sfd.Dispose();
		}
	}
示例#35
0
        private void SaveObjectList()
        {
            if (Cameras.Count == 0 && Microphones.Count == 0)
            {
                MessageBox.Show(LocRm.GetString("NothingToExport"), LocRm.GetString("Error"));
                return;
            }

            var saveFileDialog = new SaveFileDialog
                                 {
                                     InitialDirectory = _lastPath,
                                     Filter = "iSpy Files (*.ispy)|*.ispy|XML Files (*.xml)|*.xml"
                                 };

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;

                if (fileName.Trim() != "")
                {
                    SaveObjects(fileName);
                    try
                    {
                        var fi = new FileInfo(fileName);
                        _lastPath = fi.DirectoryName;
                    }
                    catch
                    {
                    }
                }
            }
            saveFileDialog.Dispose();
        }
示例#36
0
	private void save_Click(object sender, EventArgs e)
	{
		//save
		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Title = "Save";
		dlg.Filter = "Builder settings file (*.bsf)|*.bsf|All Files (*.*)|*.*";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			try
			{
				FileStream fs = new FileStream(dlg.FileName,FileMode.Create);
				BinaryWriter bw = new BinaryWriter(fs);
				bw.Write(name.Text);
				bw.Write(filename.Text);
				bw.Write(checksum.Text);
				bw.Write(info.Text);
			
				//files
				foreach (ListViewFileItem items in files.Items)
				{
					bw.Write(items.Text);
					bw.Write(items.SubItems[1].Text);
					bw.Write(items.SubItems[2].Text);
					bw.Write(items.Offset);
					bw.Write(items.Size);
				}

				bw.Close();
				fs.Close();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}
		dlg.Dispose();
	}
示例#37
0
	private void build_Click(object sender, EventArgs e)
	{
		//build
		//check for valid data
		if (name.Text == "")
		{
			MessageBox.Show("No window title","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		if (filename.Text == "")
		{
			MessageBox.Show("No filename","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		if (info.Text == "")
		{
			MessageBox.Show("No info text","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		//check checksum is valid
		if (checksum.Text.Length != 32 && checksum.Text.Length != 0)
		{
			MessageBox.Show("Invalid Checksum value","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		if (files.Items.Count == 0)
		{
			MessageBox.Show("No files","Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Title = "Save Patch";
		dlg.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			try
			{
				//copy install.exe to new file
				File.Copy(Application.StartupPath+"\\patcher.dat",dlg.FileName, true);
				FileStream fs = new FileStream(dlg.FileName,FileMode.Append);
				BinaryWriter bw = new BinaryWriter(fs);

				//name
				write_text(bw,name.Text);
				//filename
				write_text(bw,filename.Text);
				//checksum
				if (checksum.Text == "")
				{
					bw.Write((byte) 0);
				}
				else
				{
					bw.Write((byte) 1);
					bw.Write(Encoding.ASCII.GetBytes(checksum.Text));
				}
				//info
				write_text(bw,info.Text);
				
				//files
				bw.Write((byte)files.Items.Count);
				for (int i=0; i<files.Items.Count; i++)
				{
					//action "Add/Replace" "Remove"
					if (files.Items[i].SubItems[1].Text == "Add/Replace")
						bw.Write((byte)0);
					if (files.Items[i].SubItems[1].Text == "Remove")
						bw.Write((byte)1);
					//filename
					write_text(bw,files.Items[i].Text);
					//filedata if required
					if (files.Items[i].SubItems[1].Text == "Add/Replace")
					{
						ListViewFileItem lvi = (ListViewFileItem) files.Items[i];
						FileStream fsin = new FileStream(files.Items[i].SubItems[2].Text,FileMode.Open);
						BinaryReader brin = new BinaryReader(fsin);
						if (lvi.Size == -1)
						{
							//normal file
							bw.Write((int)fsin.Length);
							bw.Write(brin.ReadBytes((int)fsin.Length));
						}
						else
						{
							//file with offset and size
							fsin.Seek(lvi.Offset, SeekOrigin.Begin);
							bw.Write(lvi.Size);
							bw.Write(brin.ReadBytes(lvi.Size));
						}
						brin.Close();
						fsin.Close();
					}
				}

				bw.Close();
				fs.Close();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}
		dlg.Dispose();
	}
示例#38
0
	private void btnInject_Click(object sender, EventArgs e)
	{
		//inject dll
		if (File.Exists(proExe.Text) == false)
		{
			MessageBox.Show("Dbpro Exe not found.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}
		if (dllList.SelectedIndex == -1)
		{
			MessageBox.Show("No dll selected.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}
		string selectedDll = Application.StartupPath + Path.DirectorySeparatorChar + "dll" + Path.DirectorySeparatorChar
			+ dllList.Items[dllList.SelectedIndex] + Path.DirectorySeparatorChar + "compress.dll";
		if (File.Exists(selectedDll) == false)
		{
			MessageBox.Show("Selected dll dir does not contain \"compress.dll\".", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}
		SaveFileDialog sfd = new SaveFileDialog();
		sfd.Title = "Save injected exe as";
		sfd.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		if (sfd.ShowDialog() == DialogResult.OK)
		{
			Cursor.Current = Cursors.WaitCursor;
			DB.proExe.InjectDll(proExe.Text, sfd.FileName, selectedDll);
			Cursor.Current = Cursors.Default;
		}
		sfd.Dispose();
	}
示例#39
0
	private void mSaveOnClick(object sender, EventArgs e)
	{
		//save exe
		if (contents.Items.Count > 0)
		{
			SaveFileDialog sfd = new SaveFileDialog();
			sfd.Filter = "Exe or Pck files (*.exe, *.pck)|*.exe;*.pck|All Files (*.*)|*.*";
			sfd.Title = "Save exe";
			if (sfd.ShowDialog() == DialogResult.OK)
			{
				Cursor.Current = Cursors.WaitCursor;
				bool dbPro = false;
				if (exeType.SelectedIndex == exeType.Items.IndexOf("DbPro"))
					dbPro = true;
				proExe.SaveExe(contents.Items, sfd.FileName, exeName.Text, dbPro, displaySettings);
				if (exeName.Text == "")
					exeName.Text = sfd.FileName;
				Cursor.Current = Cursors.Default;
			}
			sfd.Dispose();
		}
		else
		{
			//nothing to save
			MessageBox.Show("Nothing to save!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
		}
	}
示例#40
0
	private void build_Click(object sender, EventArgs e)
	{
		//build new exe
		if (Loaded_ExeName == "")
		{
			MessageBox.Show("No exe loaded!","Error!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		if (exeType.SelectedIndex == 1)
		{
			//old type
			if (Targetexe.Text == "")
			{
				MessageBox.Show("No exe name!","Error!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return;
			}
		}
		//Check files in Extern exist in Plugins and Plugins_user and effects
		bool found; //has the file been found
		foreach (ListViewItem itm in Extern.Items)
		{
			found = false;
			if (File.Exists(Plugins + itm.Text))
				found = true;
			if (File.Exists(Plugins_user + itm.Text))
				found = true;
			if (File.Exists(Effects + itm.Text))
				found = true;
			if (found == false)
			{
				//file not found
				MessageBox.Show("File :"+itm.Text+"\n\n"+"Not found in \n"+Plugins+"\nor\n"+Plugins_user+"\nor\n"+Effects,"Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return;
			}
		}

		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			FileStream fsIn = null;
			BinaryReader brIn = null;
			FileStream fsOut = null;
			BinaryWriter bwOut = null;
			FileStream fsExt = null;
			BinaryReader brExt = null;
			try
			{
				fsIn = new FileStream(Loaded_ExeName, FileMode.Open);
				brIn = new BinaryReader(fsIn);
				File.Copy(Application.StartupPath+"\\expander.dat",dlg.FileName, true);
				fsOut = new FileStream(dlg.FileName, FileMode.Append);
				bwOut = new BinaryWriter(fsOut);

				//write exe name
				bwOut.Write(Targetexe.Text.Length);
				bwOut.Write(Encoding.ASCII.GetBytes(Targetexe.Text));

				//write num of internal files
				bwOut.Write((byte) Intern.Items.Count);

				//write each internal file to patch
				foreach (ListViewFileItem itm in Intern.Items)
				{
					//name
					bwOut.Write(itm.Text.Length);
					bwOut.Write(Encoding.ASCII.GetBytes(itm.Text));
					//data
					//check if file is in <exe> or not
					if (itm.SubItems[1].Text == "<exe>")
					{
						//in <exe>
						fsIn.Seek(itm.Offset, SeekOrigin.Begin);
						//size
						bwOut.Write(itm.Size);
						//data
						bwOut.Write(brIn.ReadBytes(itm.Size));
					}
					else
					{
						//external file
						//filedata
						fsExt = new FileStream(itm.SubItems[1].Text,FileMode.Open);
						brExt = new BinaryReader(fsExt);
						//size
						bwOut.Write((int) fsExt.Length);
						//data
						bwOut.Write(brExt.ReadBytes((int) fsExt.Length));
						brExt.Close();
						fsExt.Close();
					}
				}

				//use md5 checksums?
				if (CheckSum.Checked == true)
					bwOut.Write((byte) 1);
				else
					bwOut.Write((byte) 0);

				//write num of External files
				bwOut.Write((byte) Extern.Items.Count);
				string checksum;

				foreach (ListViewFileItem itm in Extern.Items)
				{
					//write name
					bwOut.Write(itm.Text.Length);
					bwOut.Write(Encoding.ASCII.GetBytes(itm.Text));
					
					//write md5 checksum string if needed
					if (CheckSum.Checked == true)
					{
						found = false;
						if (File.Exists(Plugins + itm.Text))
						{
							fsExt = new FileStream(Plugins + itm.Text,FileMode.Open);
							found = true;
						}
						if (File.Exists(Plugins_user + itm.Text))
						{
							fsExt = new FileStream(Plugins_user + itm.Text,FileMode.Open);
							found = true;
						}
						if (File.Exists(Effects + itm.Text))
						{
							fsExt = new FileStream(Effects + itm.Text,FileMode.Open);
							found = true;
						}
						if (found == true)
						{
							//get md5 checksum
							brExt = new BinaryReader(fsExt);
							System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
							byte[] result = md5.ComputeHash(brExt.ReadBytes((int)fsExt.Length));
							checksum = BitConverter.ToString(result).Replace("-","").ToLower();
							brExt.Close();
							fsExt.Close();
							//write md5 checksum
							bwOut.Write(Encoding.ASCII.GetBytes(checksum));
						}
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.ToString(),"Error!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			finally
			{
				brIn.Close();
				fsIn.Close();
				bwOut.Close();
				fsOut.Close();
			}
		}
		dlg.Dispose();
	}
示例#41
0
        private void MenuItem19Click(object sender, EventArgs e)
        {
            if (Cameras.Count == 0 && Microphones.Count == 0)
            {
                MessageBox.Show(LocRM.GetString("NothingToExport"), LocRM.GetString("Error"));
                return;
            }

            var saveFileDialog = new SaveFileDialog
                                     {
                                         InitialDirectory = Program.AppPath,
                                         Filter = "iSpy Files (*.ispy)|*.ispy|XML Files (*.xml)|*.xml"
                                     };

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;

                if (fileName.Trim() != "")
                {
                    SaveObjects(fileName);
                }
            }
            saveFileDialog.Dispose();
        }
示例#42
0
	private void mDecompressOnClick(object sender, EventArgs e)
	{
		//decompress loaded exe
		SaveFileDialog sfd = new SaveFileDialog();
		sfd.Title = "Save decompressed exe as";
		sfd.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		//check for compress.dll to ensure exe is compressed.
		if (contents.Items.Count < 3 || contents.Items[1].Text.ToLower() != "compress.dll")
		{
			MessageBox.Show("Exe is not compressed.", "Error!",
				MessageBoxButtons.OK, MessageBoxIcon.Error);
			return;
		}
		if (sfd.ShowDialog() == DialogResult.OK)
		{
			//Make sure filenames don't match, this is really just to ensure there is a backup incase decompression fails
			if (exeName.Text == sfd.FileName)
			{
				MessageBox.Show("Compressed exe filename and decompressed exe filename must be different.", "Error!",
								MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
			Cursor.Current = Cursors.WaitCursor;
			bool dbPro = false;
			if (exeType.SelectedIndex == exeType.Items.IndexOf("DbPro"))
				dbPro = true;
			proExe.DecompressExe(contents, dbPro, this, exeName.Text, sfd.FileName);
			Cursor.Current = Cursors.Default;
		}
		sfd.Dispose();
	}
示例#43
0
	private void build_Click(object sender, EventArgs e)
	{
		//build new exe
		if (Loaded_ExeName == "")
		{
			MessageBox.Show("No exe loaded!","Error!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			return;
		}
		//Check files in Extern exist in Plugins and Plugins_user and effects
		bool found; //has the file been found
		foreach (ListViewItem itm in Extern.Items)
		{
			found = false;
			if (File.Exists(Plugins + itm.Text))
				found = true;
			if (File.Exists(Plugins_user + itm.Text))
				found = true;
			if (File.Exists(Effects + itm.Text))
				found = true;
			if (found == false)
			{
				//file not found
				MessageBox.Show("File :"+itm.Text+"\n\n"+"Not found in \n"+Plugins+"\nor\n"+Plugins_user+"\nor\n"+Effects,"Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				return;
			}
		}

		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			Build.BuildExe(dlg.FileName, Loaded_ExeName, Intern, Extern, CheckSum.Checked);
		}
		dlg.Dispose();
	}
示例#44
0
 // save drawing in bitmap DrawArea as a jpeg file
 private void menuItemSave_Click(object sender, System.EventArgs e)
 {
     ImageFormat format = ImageFormat.Gif;
     SaveFileDialog sfd = new SaveFileDialog();
     if(currentSymbol!=null)
         sfd.FileName=currentSymbol.name;
     sfd.Filter = "GIF Files(*.GIF)|*.GIF|Windows Metafile (*.EMF)|*.EMF";
     if (sfd.ShowDialog()  == DialogResult.OK) {
         if(sfd.FileName.EndsWith(".EMF")) {
             saveEmf(sfd.FileName);
         } else {
             DrawArea.Save(sfd.FileName, format );
         }
         EbnfForm.WriteLine("Rule " + currentSymbol.name + " saved to "+sfd.FileName+".");
     }
     sfd.Dispose();
 }
示例#45
0
	private void btnSave_Click(object sender, EventArgs e)
	{
		//saves a new exe or pck file using info in listview
		if (list.Items.Count == 0)
		{
			MessageBox.Show("Nothing to save.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
			return;
		}
		SaveFileDialog dlg = new SaveFileDialog();
		dlg.Title = "Save New Darkbasic Pro exe";
		dlg.Filter = "Exe Files (*.exe)|*.exe|Packfile (*.pck)|*.pck|All Files (*.*)|*.*";
		FileStream fsIn;
		BinaryReader brIn;
		FileStream fsOut;
		BinaryWriter brOut;
		FileStream fsExt = null;
		BinaryReader brExt = null;  //external file
		FileStream fsUpx;    //for read & write file for upx compression
		BinaryReader brUpx;
		BinaryWriter bwUpx;
		FileStream fsNull;  //for nulling resources
		BinaryReader brNull;
		long headPos = 0; // position of end of head
		long footPos = 0; // position of extra info at end of exe
		string upx_options = "--best --crp-ms=999999"; //command line options used with upx
		//set dialog to exePath if required
		if (exePath != "")
		{
			dlg.InitialDirectory = exePath;
			exePath = "";
		}
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			if (dlg.FileName == labName.Text)
			{
				MessageBox.Show("Need to extract files from original exe!\nChoose another filename","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return;
			}
			bool pack = true;    // is the input a .Pck file
			bool inFile = true;  // is there an input file 
			//save new exe
			if (labName.Text == "")
			{
				//no file loaded so we have to make pack file
				pack = true;
				inFile = false;
			}
			if (Path.GetExtension(dlg.FileName) == ".exe")
				pack = false;
			try
			{
				//open output file
				fsOut = new FileStream(dlg.FileName,FileMode.Create);
				brOut = new BinaryWriter(fsOut);
			}
			catch (Exception ea)
			{
				MessageBox.Show(ea.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return;
			}
			if (inFile == true)
			{
				//open input file
				try
				{
					fsIn = new FileStream(labName.Text,FileMode.Open);
					brIn = new BinaryReader(fsIn);
				}
				catch (Exception ex)
				{
					MessageBox.Show(ex.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
					return;
				}
				//if input file is not a pack file find where files start  and end
				if (pack == false)
				{
					try
					{
						string start = "PADDINGXXPAD";
						string find = "";
						byte[] pad = new byte[12] {0,0,0,0,0,0,0,0,0,0,0,0};
						byte b = 0;
						int i;
						//skip some bytes to speed it up
						fsIn.Seek(1024*60,SeekOrigin.Current);
						while (find != start && fsIn.Position < 1024*100)
						{
							b = brIn.ReadByte();
							//shift the pad array to the left
							for (i = 1; i<12; i++)
								pad[i-1] = pad[i];
							pad[11] = b;
							//conver pad array to string
							find = "";
							for (i=0; i<12; i++)
							{
								find = find + Convert.ToChar(pad[i]);
							}
						}
						//since PADDINGXXPAD may just be the start of a lot of padding continue reading
						//until a value not in PADDINGXXPAD is found
						if (find == start)
						{
							while (start.IndexOf(Convert.ToChar(b), 0) != -1)
							{
								//MessageBox.Show(start.IndexOf(Convert.ToChar(b), 0).ToString());
								b = brIn.ReadByte();
							}
							//skip back one byte
							fsIn.Seek(-1 ,SeekOrigin.Current);
						}
						else
						{
							//if we haven't found "PADDINGXXPAD" guess where end of standard exe header is
							fsIn.Seek(73728,SeekOrigin.Begin);
						}
						//input file now at end of header
						headPos = fsIn.Position;
						//find position of info at end of file
						try
						{
							int nameLength, fileLength;
							while (footPos == 0)
							{
								nameLength = brIn.ReadInt32();
								if (nameLength > 0 && nameLength < 100)
								{
									fsIn.Seek(nameLength,SeekOrigin.Current);
									fileLength = brIn.ReadInt32();
									fsIn.Seek(fileLength,SeekOrigin.Current);
								}
								else
								{
									footPos = fsIn.Position - 4;
								}
							}
						}
						catch
						{
							// do nothing here
						}
						//close infile
						brIn.Close();
						fsIn.Close();
					}
					catch (Exception ex)
					{
						MessageBox.Show(ex.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
						brIn.Close();
						fsIn.Close();
						return;
					}
				}
			}
			//go through each item in listview and append it to the output file
			foreach (ListViewItem items in list.Items)
			{
				//check location of file
				if (items.SubItems[2].Text == "<exe>")
				{
					fsIn = new FileStream(labName.Text,FileMode.Open);
					brIn = new BinaryReader(fsIn);
					//item is in exe
					if (items.Text == "Standard Exe Header" && inFile == true)
					{
						//write head
						brOut.Write(brIn.ReadBytes((int)headPos));
					}
					else
					{
						if (items.Text == "Extra or Compressed block" && inFile == true)
						{
							//write footer
							fsIn.Seek(footPos,SeekOrigin.Begin);
							brOut.Write(brIn.ReadBytes((int)(fsIn.Length-footPos)));
						}
						else
						{
							//nomal file
							int length = 0;
							string name = "";
							//seek to start of files
							fsIn.Seek(headPos,SeekOrigin.Begin);
							while (name != items.Text)
							{
								//get name length
								length = brIn.ReadInt32();
								//get name
								name = "";
								for (int i=0; i<length; i++)
									name += Convert.ToChar(brIn.ReadByte());
								length = brIn.ReadInt32();
								fsIn.Seek(length,SeekOrigin.Current);
							}
							//seek back file length
							fsIn.Seek(length-(length*2),SeekOrigin.Current);
							//write name
							brOut.Write(name.Length);
							for (int i=0; i<name.Length; i++)
								brOut.Write(name[i]);
							//check if the fie is a .dll and if we need to upx or null resources
							if (items.Text.EndsWith(".dll"))
							{
								if (chkCompress.Checked == true || chkNull.Checked == true)
								{
									//write the dll to disk
									fsUpx = new FileStream("___dll.dll", FileMode.Create);
									bwUpx = new BinaryWriter(fsUpx);
									bwUpx.Write(brIn.ReadBytes(length));
									bwUpx.Close();
									fsUpx.Close();
									if (chkNull.Checked == true)
									{
										//null resources
										//input file
										fsNull = new FileStream("___dll.dll", FileMode.Open);
										brNull = new BinaryReader(fsNull);
										//output file
										fsUpx = new FileStream("___upx.dll", FileMode.Create);
										bwUpx = new BinaryWriter(fsUpx);
										//skip dos stub
										fsNull.Seek(60, SeekOrigin.Current);
										int e_lfanew = brNull.ReadInt32();
										fsNull.Seek(e_lfanew + 4, SeekOrigin.Begin);
										//IMAGE_FILE_HEADER
										fsNull.Seek(2, SeekOrigin.Current);
										int NumberOfSections = brNull.ReadInt16();
										fsNull.Seek(12, SeekOrigin.Current);
										int SizeOfOptionalHeader = brNull.ReadInt16();
										fsNull.Seek(2, SeekOrigin.Current);
										//end of IMAGE_FILE_HEADER
										//IMAGE_OPTIONAL_HEADER
										fsNull.Seek(36, SeekOrigin.Current);
										int SectionAlignment = brNull.ReadInt32();
										fsNull.Seek(56, SeekOrigin.Current);
										//DataDirectory[16]
										//seek to resouce index
										fsNull.Seek(16, SeekOrigin.Current);
										int VirtualAddress = brNull.ReadInt32();
										int Size = brNull.ReadInt32();
										fsNull.Seek(104, SeekOrigin.Current);
										//end of IMAGE_OPTIONAL_HEADER
										//section directories
										int rsrcSize = 0; // size of resource data
										int rsrcPos = 0;  // position of resource data
										for (int r=0; r<NumberOfSections; r++)
										{
											string rName = System.Text.Encoding.ASCII.GetString(brNull.ReadBytes(8));
											if (rName.Substring(-0,5) == ".rsrc")
											{
												//resource section directory
												fsNull.Seek(8, SeekOrigin.Current);
												rsrcSize = brNull.ReadInt32();
												rsrcPos = brNull.ReadInt32();
												fsNull.Seek(16, SeekOrigin.Current);
											}
											else
											{
												fsNull.Seek(32, SeekOrigin.Current);
											}
										}
										//end of section directories
										//write upto resource data
										fsNull.Seek(0,SeekOrigin.Begin);
										bwUpx.Write(brNull.ReadBytes(rsrcPos));
										//write empty resource data
										for (int r=0; r<rsrcSize; r++)
											bwUpx.Write((byte)0);
										//write rest of file
										fsNull.Seek(rsrcSize, SeekOrigin.Current);
										bwUpx.Write(brNull.ReadBytes((int)(fsNull.Length - fsNull.Position)));
										//close files
										brNull.Close();
										fsNull.Close();
										File.Delete("___dll.dll");
										bwUpx.Close();
										fsUpx.Close();
									}
									else
									{
										File.Move("___dll.dll", "___upx.dll");
									}
									if (chkCompress.Checked == true)
									{
										//compress with upx
										Process process = Process.Start(Application.StartupPath + "\\upx.exe",upx_options + " ___upx.dll");
										process.WaitForExit();
									}
									//write to brOut
									fsUpx = new FileStream("___upx.dll", FileMode.Open);
									brUpx = new BinaryReader(fsUpx);
									length = (int) fsUpx.Length;
									//write length
									brOut.Write(length);
									//write filedata
									brOut.Write(brUpx.ReadBytes(length));
									brUpx.Close();
									fsUpx.Close();
									//delete "___upx.dll"
									File.Delete("___upx.dll");
								}
							}
							else
							{
								//write file length
								brOut.Write(length);
								//check for "_virtual.dat" and use display settings
								if (items.Text == "_virtual.dat")
								{
									//seek over display info
									fsIn.Seek(16,SeekOrigin.Current);
									//write display info
									brOut.Write(displayType.SelectedIndex);
									brOut.Write(int.Parse(displayWidth.Text));
									brOut.Write(int.Parse(displayHeight.Text));
									brOut.Write(int.Parse(displayDepth.Text));
									//write filedata
									brOut.Write(brIn.ReadBytes(length-16));
								}
								else
								{
									//write filedata
									brOut.Write(brIn.ReadBytes(length));
								}
							}
						}
					}
					brIn.Close();
					fsIn.Close();
				}
				else
				{
					//item is external file
					string name;
					name = items.Text;
					//write namelength
					brOut.Write(name.Length);
					//write name
					for (int i=0;i<name.Length;i++)
						brOut.Write(name[i]);
					//check if the fie is a .dll and if we need to upx it
					if (name.EndsWith(".dll") && chkCompress.Checked == true)
					{
						//copy dll to "___upx.dll"
						File.Copy(items.SubItems[2].Text, "___upx.dll");
						//compress with upx
						Process process = Process.Start(Application.StartupPath + "\\upx.exe",upx_options + " ___upx.dll");
						process.WaitForExit();
						//copy to output
						fsUpx = new FileStream("___upx.dll", FileMode.Open);
						brUpx = new BinaryReader(fsUpx);
						//write length
						brOut.Write((int) fsUpx.Length);
						//write filedata
						brOut.Write(brUpx.ReadBytes((int) fsUpx.Length));
						brUpx.Close();
						fsUpx.Close();
						//delete "___upx.dll"
						File.Delete("___upx.dll");
					}
					else
					{
						fsExt = new FileStream(items.SubItems[2].Text,FileMode.Open);
						brExt = new BinaryReader(fsExt);
						//write length
						brOut.Write((int)fsExt.Length);
						//check for "_virtual.dat" and use display settings
						if (name == "_virtual.dat")
						{
							//seek over display info
							fsExt.Seek(16,SeekOrigin.Current);
							//write display info
							brOut.Write(displayType.SelectedIndex);
							brOut.Write(int.Parse(displayWidth.Text));
							brOut.Write(int.Parse(displayHeight.Text));
							brOut.Write(int.Parse(displayDepth.Text));
							//write filedata
							brOut.Write(brExt.ReadBytes((int)fsExt.Length-16));
						}
						else
						{
							//write filedata
							brOut.Write(brExt.ReadBytes((int)fsExt.Length));
						}
						brExt.Close();
						fsExt.Close();
					}
				}
			}
			//close open files
			brOut.Close();
			fsOut.Close();
		}
		dlg.Dispose();
	}
示例#46
0
	private void btnDecrypt_Click(object sender, EventArgs e)
	{
		//decrypt file
		FileStream fsIn;
		BinaryReader brIn;
		FileStream fsOut;
		BinaryWriter bwOut;
		OpenFileDialog dlg = new OpenFileDialog();
		dlg.Title = "Select file to decrypt";
		dlg.Filter = "All Files (*.*)|*.*";
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			SaveFileDialog sDlg = new SaveFileDialog();
			sDlg.Title = "Save decrypted file as";
			sDlg.Filter = "Loaded file type (*"+Path.GetExtension(dlg.FileName)+")|*"+Path.GetExtension(dlg.FileName);
			sDlg.Filter += "|All Files (*.*)|*.*";
			if (sDlg.ShowDialog() == DialogResult.OK)
			{
				if (dlg.FileName == sDlg.FileName)
				{
					MessageBox.Show("Can't decrypt to input file!","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
					dlg.Dispose();
					sDlg.Dispose();
					return;
				}
				else
				{
					byte input,xor;
					xor = 0x21;
					//xor = 0xDF;
					fsIn = new FileStream(dlg.FileName,FileMode.Open);
					brIn = new BinaryReader(fsIn);
					fsOut = new FileStream(sDlg.FileName,FileMode.Create);
					bwOut = new BinaryWriter(fsOut);

					int i = (int)(fsIn.Position - fsIn.Length);
					while ((int)(fsIn.Length - fsIn.Position) > 28)
					{
						input = brIn.ReadByte();
						input = (byte)(xor ^ input);
						bwOut.Write(input);
						bwOut.Write(brIn.ReadBytes(28));
					}
					if ((int)(fsIn.Length - fsIn.Position) > 0)
					{
						input = brIn.ReadByte();
						input = (byte)(xor ^ input);
						bwOut.Write(input);
					}
					if (fsIn.Position < fsIn.Length)
					bwOut.Write(brIn.ReadBytes((int)(fsIn.Length-fsIn.Position)));

					brIn.Close();
					fsIn.Close();
					bwOut.Close();
					fsOut.Close();
				}
			}
			sDlg.Dispose();

		}
		dlg.Dispose();
	}