# ATSプラグイン 制作メモ(C#編) [c++編](https://hackmd.io/@Nepia/Hk6Owd4RU) 各関数とかの説明はこっちを用参照 ## 目次 [TOC] ## 0.準備 - VisualStudio2022≫[ダウンロード](https://visualstudio.microsoft.com/ja/vs/) - TetsuOtterさんのAtsテンプレート≫[ダウンロード](https://github.com/TetsuOtter/BVE_ATSPITemp) ### 0.1 DLLExportをインストールする `BVE_ATSPlTemp.sln`をダブルクリックで起動  `OK`をクリック  右上の検索窓に`NuGet`と入力、`Nugetパッケージの管理をクリック`  `参照`タブに切り替え、検索窓に`DLLExport`と入力、`インストール`をクリック  `OK`をクリック  PlTempCSを選択して`Apply`をクリック  `すべて再読み込み`をクリック  ### 0.2 ビルド `Ctl+B`でビルド、成功すれば完了  --- ## 1. 各関数 省略 こっちみて≫[c++編](https://hackmd.io/@Nepia/Hk6Owd4RU) ## 2. ファイルの読み込み ### 2.1 サンプル `SampleCSVReader.cs` ```csharp=1 using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace PITempCS.module { // CSVファイル読み込みサンプルプログラム public class CSVReaderSample { const int DONE = 0; const int ERR = 1; string filePath; bool loaded; // インスタンス生成 public CSVReaderSample() { filePath = ""; loaded = false; } // 初期化メソッド private int init(string fileName) { // AtsPluginの自DLLパス string path = System.Reflection.Assembly.GetExecutingAssembly().Location; // ファイルパスの文字数 int pathLength = path.Length; // ファイルパスの後ろから'\'を検索 int index = path.LastIndexOf('\\'); // '\'が見つからなかったとき if (index < 0) { return ERR; } // 実行DLL名を削除 path = path.Remove(index+1, pathLength-index-1); try { // ファイルを開く FileStream file = File.Open(path + fileName, FileMode.Open); file.Close(); } catch (FileNotFoundException fnfex) { // ファイルが見つからないとき MessageBox.Show(fnfex.Message, "[init]Error"); return ERR; } // ファイル読み込み可能フラグを立てる loaded = true; // ファイルパスを保存 filePath = path + fileName; return DONE; } // ファイル読み込みメソッド private int readFile(List<List<string>> list) { // 初期化処理が呼ばれていない/ファイルが読み込めないとき if (loaded == false) { return ERR; } // リスト初期化 list.Clear(); try { // ファイルを開く StreamReader file = new StreamReader(filePath); // ファイル末尾まで繰り返す while (!file.EndOfStream) { // 一行を読む string line = file.ReadLine(); // カンマ毎に分けて配列にいれる string[] values = line.Split(','); // 配列からリストに変換 List<string> lists = new List<string>(); lists.AddRange(values); // リストに1レコードとしてぶち込む list.Add(lists); } // ファイルを閉じる file.Close(); } catch (FileNotFoundException fnfex) { // ファイルが見つからないとき MessageBox.Show(fnfex.Message, "[readFile]Error"); return ERR; } return DONE; } // ファイル読み込みメソッド public int readFile(ref List<List<string>> list, string fileName) { // 返値 int ret; // 初期化 ret = init(fileName); if (ret != 0) { // ファイルがないとき return ERR; } // ファイル読み込み ret = readFile(ref list); if (ret != 0) { // ファイルが読み込めないとき return ERR; } return DONE; } } } ``` ### 2.2 パスの取得 自DLLの絶対パスが文字列型で取得できる `System.Reflection.Assembly.GetExecutingAssembly().Location;` ```csharp=1 String path = System.Reflection.Assembly.GetExecutingAssembly().Location; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up