コード例 #1
0
        private void cmdCreate_Click(object sender, EventArgs e)
        {
            // ask for output file
            string fileName = new System.IO.DirectoryInfo(txtRoot.Text + @"\").Name;

            char[] invalid = System.IO.Path.GetInvalidFileNameChars();
            for (int i = 0; i < invalid.Length; i++)
            {
                fileName = fileName.Replace(invalid[i].ToString(), "");
            }

            saveFileDialog1.DefaultExt = "html";
            if (!fileName.ToLower().EndsWith(".html"))
            {
                fileName += ".html";
            }
            saveFileDialog1.FileName         = fileName;
            saveFileDialog1.Filter           = "HTML files (*.html)|*.html|All files (*.*)|*.*";
            saveFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(txtRoot.Text);
            saveFileDialog1.CheckPathExists  = true;
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (!saveFileDialog1.FileName.ToLower().EndsWith(".html"))
            {
                saveFileDialog1.FileName += ".html";
            }

            // begin generating html
            var settings = new SnapSettings()
            {
                rootFolder      = txtRoot.Text,
                title           = txtTitle.Text,
                outputFile      = saveFileDialog1.FileName,
                skipHiddenItems = !chkHidden.Checked,
                skipSystemItems = !chkSystem.Checked,
                openInBrowser   = chkOpenOutput.Checked,
                linkFiles       = chkLinkFiles.Checked,
                linkRoot        = txtLinkRoot.Text,
            };

            StartProcessing(settings);
        }
コード例 #2
0
        private void cmdCreate_Click(object sender, EventArgs e)
        {
            // ensure source path format
            txtRoot.Text = System.IO.Path.GetFullPath(txtRoot.Text);
            if (txtRoot.Text.EndsWith(@"\"))
            {
                txtRoot.Text = txtRoot.Text.Substring(0, txtRoot.Text.Length - 1);
            }
            if (IsWildcardMatch("?:", txtRoot.Text, false))
            {
                txtRoot.Text += @"\";                                                   // add backslash to path if only letter and colon eg "c:"
            }
            // add slash or backslash to end of link (in cases where it is clearthat we we can)
            if (!txtLinkRoot.Text.EndsWith(@"/") && txtLinkRoot.Text.ToLower().StartsWith(@"http"))                     // web site
            {
                txtLinkRoot.Text += @"/";
            }
            if (!txtLinkRoot.Text.EndsWith(@"\") && IsWildcardMatch("?:*", txtLinkRoot.Text, false))                    // local disk
            {
                txtLinkRoot.Text += @"\";
            }

            // get output file
            if (outFile == "")
            {
                string fileName = new System.IO.DirectoryInfo(txtRoot.Text + @"\").Name;
                char[] invalid  = System.IO.Path.GetInvalidFileNameChars();
                for (int i = 0; i < invalid.Length; i++)
                {
                    fileName = fileName.Replace(invalid[i].ToString(), "");
                }

                saveFileDialog1.DefaultExt = "html";
                if (!fileName.ToLower().EndsWith(".html"))
                {
                    fileName += ".html";
                }
                saveFileDialog1.FileName         = fileName;
                saveFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(txtRoot.Text);
                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }
            else // command line
            {
                saveFileDialog1.FileName = outFile;
            }

            if (!saveFileDialog1.FileName.ToLower().EndsWith(".html"))
            {
                saveFileDialog1.FileName += ".html";
            }

            // make sure output path exists
            if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(saveFileDialog1.FileName)))
            {
                MessageBox.Show("The output folder does not exists...\n\n" + System.IO.Path.GetDirectoryName(saveFileDialog1.FileName), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // begin generating html
            Cursor.Current      = Cursors.WaitCursor;
            this.Text           = "Snap2HTML (Working... Press Escape to Cancel)";
            tabControl1.Enabled = false;
            backgroundWorker.RunWorkerAsync();
        }