2016-09-21 3 views
0

Here's a GIF showing whats wrong
NOTEをロードするときにアセンブリ名の文字列が正しいレンダリングイマイチそれは正しい名前とパスではありません。C#のエグゼ


テストするには.exeが必要ですか?
https://github.com/ImReallyShiny/SAIO/blob/master/Test.exe
(必要であれば、それをスキャンし、しかし、それは100%安全です)


これが起こっている絶対的な魔法です。

Visual Studioの[スタート]ボタンから "自動更新"コードを実行すると、正しいファイルパスとファイル名(.exe)が出力されます...
しかし、 .exe、それはいくつかの魔法をかけることになります(&を含む)。

私は理由として見ることができる唯一のことは、両方のWebClientでコードが正確に同じです.Webclientに問題があります(ただし、文字列varに結び付けられています。 )または私のVisualStudioのセットアップとグリッチのいくつかの種類(キャッシュ、プロパゲーション、PCの再起動が必要か何か)


これは説明するのは難しい質問です、だから私はいくつかのインラインが問題がどこにあるかを説明するコメントを追加し、どのようなそうです。

コード:

//Using WebClient, get the Newest File Version; 
using (System.Net.WebClient wc = new System.Net.WebClient()) 
{ 

    //Latest Version; (This is the number after the - for the filename - Excluding .exe) 
    string LatestVersion = wc.DownloadString("https://raw.githubusercontent.com/ImReallyShiny/SAIO/master/version.txt"); 
    //This is the Location itself e.g C:/Users/Shiny/Desktop/{appname}.exe 
    string ExecutableLocation = typeof(Program).Assembly.CodeBase.Replace("file:///", ""); 
    //The build's File Version; 
    string CurrentVersion = FileVersionInfo.GetVersionInfo(ExecutableLocation).ProductVersion; 
    //Final Name String; As you can see it SHOULD output as: AppName-1.2.4.5.exe 
    string CurrentExecutableName = typeof(Program).Assembly.GetName().Name + "-" + LatestVersion + ".exe"; 

    //If the Latest Version is Newer then the Current Version; 
    if (LatestVersion != CurrentVersion) 
    { 

     //Download the Latest Version of the EXE file; (Gets the name and path perfectly fine) 
     wc.DownloadFile("https://github.com/ImReallyShiny/SAIO/raw/master/SAIO.exe", CurrentExecutableName); 

     //Show a MessageBox asking to open Explorer to the file; - This should output "{Path}/AppName-1.2.4.5.exe" but it only does when opening from VS 
     DialogResult mb = MessageBox.Show("Continue usage on the new update. Open Explorer and go to the Directory containing the updated .exe located at: " + ExecutableLocation.Replace("SAIO.EXE", CurrentExecutableName + " ?\""), "New Update Downloaded!", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); 
     if (mb == DialogResult.Yes) 
     { 
      //Go to where SAIO is and select the New Update.exe; (This also fails to select the right .exe, It selects "SAIO.EXE" when it should be selecing the AppName-1.2.4.5.exe 
      Process.Start("explorer.exe", "/select,\"" + ExecutableLocation.Replace("/", "\\").Replace("SAIO.EXE", CurrentExecutableName) + "\""); 
     } 

    } 
    else 
    { 

     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Application.Run(new MainForm()); 

    } 

} 

イムを言って何をゲット?

答えて

0

これは、単にファイル名が(時には)SAIO.exeまたはその他の場合です。 Replaceとして見

は、最善の解決策は、1つのSAIO.EXEするだけでそこを期待するのではなく、あなたが望む完全なフォルダ名を取得するためにPath.GetDirectoryNameを使用することですあなたがInvariantCultureIgnoreCase(またはsomethingElseIgnoreCase)を指定できるように過負荷を持っていませんパスで。

など。あなたの最後の行は、(未テスト)のようになります。

Process.Start("explorer.exe", "/select,\"" + 
    Path.GetDirectoryName(ExecutableLocation.Replace("/", "\\")) 
    + "\\" + CurrentExecutableName + "\""); 

GetDirectoryNameは細かい/セパレータを処理していますが、それでもいつかきちんと作品へexplorer通話を確保するためにそれらを調整するとよいでしょう。

本当に最後の行は(再びテストされていない)でなければなりません:

Process.Start("explorer.exe", "/select,\"" + 
    Path.Combine(Path.GetDirectoryName(ExecutableLocation.Replace("/", "\\")), 
     CurrentExecutableName) + "\"");