いらない自作アプリ(個人用)苦笑交じり(´・ω・`)

2016.08.07

Logging


いらない自作アプリをVC#で作りました(´・ω・`)。
殆どの人がいらないと思うアプリですが
自分にとっては、結構重宝するアプリだったりします。
ちなみにプロセスの管理とかしていないので
エラーで落ちちゃう恐れとかあります。
そこはご愛嬌でよろしくお願いします。
中身のコードは少し他人のコードを
コピペで使わさせてもらっている所ありです。
また、解像度によりうまく表示されない事もあります。
まさに、自分だけのためのアプリなのです。
(そんな場合は最大化www)
これで何が出来るのかといえば・・・
httpd.confのバーチャルホスト設定のファイル作成を
自動で吐き出してくれます。ついでにhostsファイルも
吐き出します。
コードはこんな感じ。
DLしたい奇特な方用:https://zip358.com/tool/httpconf.zip

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace httpdconf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void make_btn_Click(object sender, EventArgs e)
        {
            Boolean flg_1;
            Boolean flg_2;
            Boolean flg_3;
            string conf_str;
            string stCurrentDir = System.Environment.CurrentDirectory;
            flg_1 = chk_text(host_name.Text);
            flg_2 = chk_text(ip_address.Text);
            flg_3 = chk_text(dc_root.Text);
            if (flg_1 && flg_2 && flg_3) {
                conf_str = @"
<VirtualHost *:80>
DocumentRoot " + dc_root.Text + host_name.Text + @"
ServerName " + host_name.Text + @"
" + option_text.Text + @"
ErrorLog logs/virtual.host-" + host_name.Text + @"-error_log
CustomLog logs/virtual.host-access-" + host_name.Text + @"_log combined
</VirtualHost>";
                midashi.Text = conf_str;
                IPAD.Text = ip_address.Text + " " + host_name.Text;
                wte(stCurrentDir, "/vhost-" + host_name.Text, midashi, "conf");
                wte(stCurrentDir, "/hosts_win_" + host_name.Text, IPAD, "txt");
                System.Diagnostics.Process.Start(stCurrentDir);
            }
        }
        public Boolean chk_text(string str) {
            if (str == "") {
                return (false);
            }
            return (true);
        }
        public void wte(string dir, string fname, TextBox txt_str, string ext)
        {
            System.IO.StreamWriter sw = new System.IO.StreamWriter(
                dir + fname + "." + ext,
                false,
                System.Text.Encoding.GetEncoding("utf-8"));
            foreach (string line in txt_str.Lines)
            {
                sw.Write(line + sw.NewLine);
            }
            sw.Close();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.LinkVisited = true;
            System.Diagnostics.Process.Start("https://twitter.com/zip358com");
        }
    }
}

動作画面

タグ

AM, Boolean flg, host_name.Text, LinkLabelLinkClickedEventArgs e, namespace httpdconf, new System.IO.StreamWriter, object sender, private void linkLabel1_LinkClicked, public partial class Form1, stCurrentDir, string stCurrentDir, System.Diagnostics.Process.Start, System.Environment.CurrentDirectory, System.IO.StreamWriter sw, System.Text.Encoding.GetEncoding, using System.Collections.Generic, using System.ComponentModel, using System.Drawing, using System.Threading.Tasks, using System.Windows.Forms, virtual.host,