コード例 #1
0
        private int ExportToReg(List <List <string> > infoList, int tagList)
        {
            try
            {
                // Templatesキーを一度削除
                if (Registry.CurrentUser.OpenSubKey(@"Software\ASR_UserTools\makeNewFile\Templates", false) != null)
                {
                    RegistryKey parentRegTree = Registry.CurrentUser.OpenSubKey(@"Software\ASR_UserTools\makeNewFile\", true);
                    parentRegTree.DeleteSubKeyTree("Templates");
                    parentRegTree.Close();
                }

                RegistryKey regTemplates = Registry.CurrentUser.CreateSubKey(@"Software\ASR_UserTools\makeNewFile\Templates", true);

                int count = infoList.Count();
                regTemplates.SetValue("count", count);
                regTemplates.SetValue("tagList", tagList);

                for (int i = 0; i < count; i++)
                {
                    string tagList_2 = Convert.ToString(tagList, 2).PadLeft(count, '0');
                    if (tagList_2.Substring(i, 1) == "0")
                    {
                        regTemplates.SetValue("headerTitle_" + i.ToString(), infoList[i][0]);
                        regTemplates.SetValue("isEnabled_" + i.ToString(), infoList[i][1]);
                        regTemplates.SetValue("targetExtension_" + i.ToString(), infoList[i][2]);
                        ExportToText exportToText = new ExportToText();
                        regTemplates.SetValue("defaultText_" + i.ToString(), exportToText.Export(infoList[i][3]));
                        regTemplates.SetValue("charasetIndex_" + i.ToString(), int.Parse(infoList[i][4]));
                    }
                    else
                    {
                        regTemplates.SetValue("headerTitle_" + i.ToString(), infoList[i][0]);
                        regTemplates.SetValue("isEnabled_" + i.ToString(), infoList[i][1]);
                        regTemplates.SetValue("targetExtension_" + i.ToString(), infoList[i][2]);
                        regTemplates.SetValue("sizeX_" + i.ToString(), int.Parse(infoList[i][3]));
                        regTemplates.SetValue("sizeY_" + i.ToString(), int.Parse(infoList[i][4]));
                        regTemplates.SetValue("backgroundColor_" + i.ToString(), infoList[i][5]);
                    }
                }

                regTemplates.SetValue("BmpExtensions", tp.BMP_Extensions.Text);
                regTemplates.SetValue("GifExtensions", tp.GIF_Extensions.Text);
                regTemplates.SetValue("JpegExtensions", tp.JPEG_Extensions.Text);
                regTemplates.SetValue("PngExtensions", tp.PNG_Extensions.Text);
                regTemplates.SetValue("TiffExtensions", tp.TIFF_Extensions.Text);
                regTemplates.SetValue("WmpExtensions", tp.WMP_Extensions.Text);
                regTemplates.SetValue("OfficeSpreadsheetBIFFExtensions", tp.OfficeSpreadsheet_BIFF_Extensions.Text);
                regTemplates.SetValue("OfficeSpreadsheetOOXMLExtensions", tp.OfficeSpreadsheet_OOXML_Extensions.Text);

                regTemplates.Close();

                return(0);
            }
            catch (Exception)
            {
                return(1);
            }
        }
コード例 #2
0
        /// <summary>
        /// エラーがなくレジストリへの書き込みまで終了した場合に0を返す。エラーが出た場合は1を返す。
        /// </summary>
        /// <returns></returns>
        public int Export()
        {
            List <List <string> > regInfo = new List <List <string> >();
            string tagList = "";    // タイプの種類を2進数で表す
            bool   isOK    = true;

            foreach (var childGroupBox in LogicalTreeHelper.GetChildren(tp.TemplatesField))
            {
                if (childGroupBox is DependencyObject)
                {
                    if (isOK && (string)((System.Windows.Controls.GroupBox)childGroupBox).Tag == "Text")
                    {
                        List <string> result = new List <string>();
                        result = GetTextGropBoxInfo((System.Windows.Controls.GroupBox)childGroupBox);
                        if (result.Count() != 0)
                        {
                            regInfo.Add(result);
                            tagList += "0";
                        }
                        else
                        {
                            isOK = false;
                        }
                    }
                    else if (isOK && (string)((System.Windows.Controls.GroupBox)childGroupBox).Tag == "Image")
                    {
                        List <string> result = new List <string>();
                        result = GetImageGropBoxInfo((System.Windows.Controls.GroupBox)childGroupBox);
                        if (result.Count() != 0)
                        {
                            regInfo.Add(result);
                            tagList += "1";
                        }
                        else
                        {
                            isOK = false;
                        }
                    }
                }
            }

            if (isOK == false)
            {
                System.Windows.MessageBox.Show("エラーが発生したため、処理を中止しました。\nデータが正しく入力されていることを確認してください。", "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
                return(1);
            }

            // 入力の整合性を確認する。
            List <string> formatExtList = new List <string>();

            formatExtList.Add(tp.BMP_Extensions.Text);
            formatExtList.Add(tp.GIF_Extensions.Text);
            formatExtList.Add(tp.JPEG_Extensions.Text);
            formatExtList.Add(tp.PNG_Extensions.Text);
            formatExtList.Add(tp.TIFF_Extensions.Text);
            formatExtList.Add(tp.WMP_Extensions.Text);
            formatExtList.Add(tp.OfficeSpreadsheet_BIFF_Extensions.Text);
            formatExtList.Add(tp.OfficeSpreadsheet_OOXML_Extensions.Text);

            CheckValue checkValue = new CheckValue();
            // フォーマットに対応する拡張子の登録に二重登録されているものがないか確認
            List <string> res_01 = checkValue.CheckFormatRegistration(formatExtList);

            if (res_01.Count() != 0)
            {
                System.Windows.MessageBox.Show("同一の拡張子が複数のフォーマットに登録されています。\nデータを正しく修正してください。\n対象の拡張子 : " + string.Join(",", res_01), "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
                return(1);
            }

            // テンプレートの拡張子の整合性確認(有効化されているもののみ)
            // 画像フォーマットに関連付けられた拡張子は、テキストテンプレートとして登録されていてはならない。
            // その逆があってもならない。
            List <string> imageFormatExtList = new List <string>();

            imageFormatExtList.Add(tp.BMP_Extensions.Text);
            imageFormatExtList.Add(tp.GIF_Extensions.Text);
            imageFormatExtList.Add(tp.JPEG_Extensions.Text);
            imageFormatExtList.Add(tp.PNG_Extensions.Text);
            imageFormatExtList.Add(tp.TIFF_Extensions.Text);
            imageFormatExtList.Add(tp.WMP_Extensions.Text);

            List <string> res_02 = checkValue.CheckFormatsOfTemplates(regInfo, imageFormatExtList);

            if (res_02.Count() != 0)
            {
                System.Windows.MessageBox.Show("有効化されているテンプレートに登録されている拡張子と、フォーマットに登録されている拡張子の情報に差異があります。\nデータを正しく修正してください。\n対象のテンプレート : " + string.Join(",", res_02), "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
                return(1);
            }

            List <string> res_03 = checkValue.CheckWildCard(regInfo);

            if (res_03.Count() != 0)
            {
                System.Windows.MessageBox.Show("対象の拡張子を、ワイルドカードを用いて設定することはできません。\nデータを正しく修正してください。\n対象のテンプレート : " + string.Join(",", res_03), "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
                return(1);
            }

            ExportToText exportToText = new ExportToText();

            if (exportToText.Clear() == 1)
            {
                System.Windows.MessageBox.Show("設定の書き出しに失敗しました。権限によりブロックされている可能性があります。", "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            int tagListNum = Convert.ToInt32(tagList, 2);
            int res_04     = ExportToReg(regInfo, tagListNum);

            if (res_04 == 1)
            {
                System.Windows.MessageBox.Show("レジストリへの設定の書き出しに失敗しました。権限によりブロックされている可能性があります。", "エラー通知", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(0);
        }