2012-06-16 3 views
2

나는 업데이트 시스템을 만들기 시작하고 어떻게 든 작동하지 않는다는 것을 제외하면 멋지게 작동하는 프로그램을 만들고 있습니다. 스플래시 화면에서 WebClient를 사용하여 업데이트가 있는지 확인합니다. 이제는 오류가있는 것처럼 보입니다. 스플래시 화면에서 텍스트 파일을 다운로드하도록 설정했습니다. 버전이 일치하지 않으면 별도의 양식이 시작되고 WebClient를 사용하여 업데이터를 다운로드합니다. 이 양식을 두 번 만들었습니다. 1 개의 progressBar, 1 개의 WebClient, 이미지 배경 및 1 개의 라벨이 있습니다. 업데이트는 다운로드하고 진행률을 막대에 표시 한 다음 업데이터를 열고 기본 프로그램을 닫습니다. 처음으로 양식을 만들었을 때 나는 그것을 돌렸고 파일이 다운되지 않고 동결되었습니다. 디버깅을 중단 한 후 Visual C# 2010의 디자인 창이 충돌하고 vC#을 다시 시작해야했습니다. 창에 webClient를 제외한 모든 항목이 표시됩니다. 그래서 나는 다시 디버깅을 시도하고 나는이 메시지를 가지고있다.WebClient가 "인코딩 할 수있는 데이터가 없습니다. 1252"

Error 1 Invalid Resx file. Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip 

Error 2 TargetInvocationException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. 
at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader) 
at System.Resources.ResXResourceReader.EnsureResData() 
at System.Resources.ResXResourceReader.GetEnumerator() 
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(ReaderInfo readerInfo, IResourceReader reader, String fileName) 
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(String filename, Boolean shouldUseSourcePath) 
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFileOrDir) 
XmlException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. Line 138, position 5. 

NotSupportedException: No data is available for encoding 1252. 
at System.Text.BaseCodePageEncoding.LoadCodePageTables() 
at System.Text.BaseCodePageEncoding..ctor(Int32 codepage, Int32 dataCodePage) 
at System.Text.SBCSCodePageEncoding..ctor(SerializationInfo info, StreamingContext context) 
C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip 

그래서 폼에서 webClient를 삭제하고 다시 시도했다. 나는 두 번째 동일한 오류가있어. 그래서 나는 첫 번째 오류를 봤는데, 고침과 함께 hackforums에 하나의 응답을 발견했다. 그리고 지금 전 완전히 잃어버린 것입니다. 내 모든 웹 클라이언트는 지금이 일을하고있는 것처럼 보입니다. 이유는 모르겠습니다. 여기

는 나의 시작 화면에서 코드입니다 :

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Net; 

namespace TubeRip 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     timer1.Start(); 
     getupdates(); 
    } 

    private void timer1_Tick(object sender, EventArgs e) 
    { 
     timer2.Start(); 
    } 

    private void timer2_Tick_1(object sender, EventArgs e) 
    { 
     timer1.Stop(); 
     label1.Text = "Loading Core Components..." + " " + progressBar1.Value.ToString() + "%"; 

     if (progressBar1.Value < 20) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      timer3.Start(); 
     } 
    } 
    private void end() 
    { 
     timer7.Stop(); 
     mainpage home = new mainpage(); 
     home.Show(); 
     this.Dispose(false); 
    } 

    private void timer3_Tick(object sender, EventArgs e) 
    { 
     timer2.Stop(); 
     label1.Text = "Loading Encryption Algorithyms..." + " " + progressBar1.Value.ToString() + "%"; 
     if (progressBar1.Value < 40) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      timer4.Start(); 
     } 
    } 

    private void timer4_Tick(object sender, EventArgs e) 
    { 
     timer3.Stop(); 
     label1.Text = "Enabling Download Services..." + " " + progressBar1.Value.ToString() + "%"; 
     if (progressBar1.Value < 60) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      timer5.Start(); 
     } 

    } 

    private void timer5_Tick(object sender, EventArgs e) 
    { 
     timer4.Stop(); 
     label1.Text = "Disabling Youtube's Download Protection..." + " " + progressBar1.Value.ToString() + "%"; 
     if (progressBar1.Value < 80) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      timer6.Start(); 
     } 

    } 

    private void timer6_Tick(object sender, EventArgs e) 
    { 
     timer5.Stop(); 
     label1.Text = "Drawing GUI" + " " + progressBar1.Value.ToString() + "%"; 
     if (progressBar1.Value < 90) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      timer7.Start(); 
     } 
    } 

    private void timer7_Tick(object sender, EventArgs e) 
    { 
     timer6.Stop(); 
     label1.Text = "Creating The first Humanlike Robot..." + " " + progressBar1.Value.ToString() + "%"; 
     if (progressBar1.Value < 100) 
     { 
      progressBar1.Value += 1; 
     } 
     else 
     { 
      end(); 
     } 
    } 
    private void getupdates() 
    { 
     try 
     { 
      string updateurl = "http://dl.dropbox.com/u/22054429/TubeRip_version.txt"; 
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateurl); 
      WebResponse response = request.GetResponse(); 
      System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("windows-1252")); 
      string update = sr.ReadToEnd(); 
      int build = Convert.ToInt32(update); 
      int thisbuild = 2; 
      if (build > thisbuild) 
      { 
       label2.Visible = true; 
       TubeRip.Properties.Settings.Default.UpdateAvail = true; 
      } 
      else 
      { 
       label2.Visible = false; 
       TubeRip.Properties.Settings.Default.UpdateAvail = false; 
      } 
     } 
     catch 
     { 
      MessageBox.Show("Unable to connect to update server! Please try again later."); 
     } 
    } 

} 
} 

그리고 여기 내 업데이트 프로그램의 코드입니다 : 내 특정 오류에 어떤 결과를 찾을 수 없습니다

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Diagnostics; 
using System.Net; 

namespace TubeRip 
{ 
public partial class updates : Form 
{ 
    public updates() 
    { 
     InitializeComponent(); 
    } 

    private void updates_Load(object sender, EventArgs e) 
    { 
     Uri update = new Uri("http://dl.dropbox.com/u/22054429/TubeRip_Installer.exe"); 
     webClient1.DownloadFileAsync(update, "update.exe"); 
     webClient1.DownloadProgressChanged +=new DownloadProgressChangedEventHandler(webClient1_DownloadProgressChanged); 
     webClient1.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient1_DownloadFileCompleted); 
    } 
    void webClient1_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) 
    { 
     Process.Start("update.exe"); 
     Environment.Exit(0); 
    } 
    void webClient1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) 
    { 
     progressBar1.Value = e.ProgressPercentage; 
     label1.Text = "Downloading Updates Please Wait... " + e.ProgressPercentage.ToString() + "%"; 
    } 
} 
} 
+0

어느 누구도이 문제를 해결할 수 없으므로이 오류가 발생하지 않는 웹 클라이언트에서 UTF-8 인코딩을 사용하기로 결정했습니다. –

답변

1

,하지만 난을 찾았어요 그것을 해결하는 방법. WebClient에 기본 인코딩을 사용하는 대신 인코딩 자체를 UTF-8로 설정합니다.이 오류는이 오류를 발생시키지 않습니다. 수정 된 코드는 결국 작동하게되었습니다.

WebClient client = new WebClient(); 
client.Encoding = System.Text.Encoding.UTF8; 
Uri update = new Uri(uri); 
client.DownloadFileAsync(update, "update.exe"); 
client.DownloadProgressChanged +=new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); 
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); 

그렇지 않으면이 문제점에 대한 수정 사항이 발견되지 않으며이 문제가 표시 될 이유가 없습니다.

관련 문제