コード例 #1
0
ファイル: Program.cs プロジェクト: rinmon/KIKaikeiSystem
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length == 0)
            {
                Application.Run(new FormMain());
            }
            else
            {
                string command = args[0];

                string serverUrl   = Properties.Settings.Default.server;
                string serviceName = Properties.Settings.Default.service;
                string accountId   = Properties.Settings.Default.accountId;
                string password    = Properties.Settings.Default.password;

                string binName = Properties.Settings.Default.binaryName;
                string binPath = Environment.CurrentDirectory + "\\" + binName;
                int    currentVersion;
                try {
                    System.Diagnostics.FileVersionInfo ver =
                        System.Diagnostics.FileVersionInfo.GetVersionInfo(binPath);
                    currentVersion = ver.ProductMajorPart * 10000 + ver.ProductMinorPart;
                }
                catch (Exception) {
                    currentVersion = 0;
                }

                bool          res    = false;
                LicenseClient client = new LicenseClient(serverUrl, serviceName, accountId, password);

                if (command == "update")
                {
                    res = CommandExecutor.Update(client, currentVersion, Environment.CurrentDirectory, binName, false);
                }
                else if (command == "update-silent")
                {
                    res = CommandExecutor.Update(client, currentVersion, Environment.CurrentDirectory, binName, true);
                }
                else if (command == "getlicense")
                {
                    res = CommandExecutor.GetLicense(client, Environment.CurrentDirectory + "\\" + Properties.Settings.Default.licenseFileName);
                }

                if (res == true)
                {
                    //MessageBox.Show("正常終了しました", "License manager");
                }
                else
                {
                    //MessageBox.Show("異常終了", "License manager");
                }
            }
        }
コード例 #2
0
ファイル: FormMain.cs プロジェクト: rinmon/KIKaikeiSystem
        private void FormMain_Load(object sender, EventArgs e)
        {
            serverUrl   = Properties.Settings.Default.server;
            serviceName = Properties.Settings.Default.service;
            accountId   = Properties.Settings.Default.accountId;
            password    = Properties.Settings.Default.password;

            binName = Properties.Settings.Default.binaryName;
            binPath = Environment.CurrentDirectory + "\\" + binName;

            client = new LicenseClient(serverUrl, serviceName, accountId, password);

            CommandExecutor.PrintLogMsg += PrintLogMsg;
        }
コード例 #3
0
 public static bool GetLicense(LicenseClient client, string fileName)
 {
     return(client.DownloadLicenseFile(fileName));
 }
コード例 #4
0
        public static bool Update(LicenseClient client, int currentVersion, string targetDir, string targetBinName, bool silent = false)
        {
            int lastVersion = client.GetLastVersion();

            // Error
            if (lastVersion == -1)
            {
                MessageBox.Show("サーバとの接続に失敗しました。ネットワーク接続に問題があるか、アカウントの設定が間違えています。", "license client");
                return(false);
            }

            PrintLogMsg("現行バージョン:" + currentVersion);
            PrintLogMsg("最新バージョン:" + lastVersion);

            if (lastVersion <= currentVersion)
            {
                if (silent == false)
                {
                    MessageBox.Show("新しいアップデートは存在しません", "license client");
                }
                return(false);
            }

            DialogResult res = MessageBox.Show("新しいバージョンが存在します。アップデートを実行しますか?", "license client", MessageBoxButtons.YesNo);

            if (res != DialogResult.Yes)
            {
                return(false);
            }

            string fileName;

            try {
                fileName = System.IO.Path.GetTempFileName();
            }
            catch (System.IO.IOException) {
                MessageBox.Show("一時ファイルの作成に失敗しました。システムの一時ファイルのフォルダを整理してください。");
                return(false);
            }

            if (client.DownloadBinary(lastVersion, fileName) == false)
            {
                MessageBox.Show("ダウンロードに失敗しました", "license client");
                return(false);
            }

            if (!silent)
            {
                if (CommandExecutor.ExitTargetProcess(targetDir, targetBinName) == false)
                {
                    MessageBox.Show(targetBinName + "の終了に失敗しました。");
                    return(false);
                }
            }

            if (ExtractZipFile(fileName, targetDir) == false)
            {
                MessageBox.Show("ファイルの展開に失敗しました", "license client");
                return(false);
            }

            if (System.IO.File.Exists(fileName))
            {
                try {
                    System.IO.File.Delete(fileName);
                }
                catch (Exception) {
                    MessageBox.Show("一時ファイルの削除に失敗しました。", "license client");
                }
            }

            PrintLogMsg("Version" + lastVersion + "に更新しました。");
            MessageBox.Show("正常終了", "license client");

            return(true);
        }