Witajcie mam problem z kodem, gdy próbuje dopisać do pliku "FilePath = ". Dostaję błąd od kompilatora taki jak w temacie.
Prosiłbym o pomoc, i o wymienienie gdzie jest błąd, i o ewentualną pomoc w optymalizacji. Z góry przepraszam za nieprzejrzystość kodu.
Główna klasa :
using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;
using System.Data;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Collections;
namespace Szyfrowanie
{
class RijndaelSample
{
//BILBIOTEKI
[DllImport("user32.dll")]
static extern short GetKeyState(int nVirtKey);
//ZMIENNE GLOBALNE
static int PoprawkaDoSzerokości = 18;
static int odliczanie = 0;
static string @PATH = null;
static bool for_Nas = false;
static string TEMP = "";
static string @Appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Apps by DjCorax";
static string @FileAppdata = Appdata + "\\config.txt"; // Jeżeli będzie działać (A powinno), dam rozszerzenie *.cfg
static ArrayList tekst = new ArrayList();
static StreamReader SR,AppR;
static StreamWriter SW;
//TABLICE
static string[] menu = {"══════════════════════════════════════════════════", "1. Szyfrowanie", "2. Deszyfrowanie", "3. Opcje", " @DjCorax 2013","══════════════════════════════════════════════════", };
//WĄTKI
static Thread spr_wla = new Thread(new ThreadStart(SprawdzanieWlasciwosci));
static Thread draw = new Thread(new ThreadStart(Draw));
static Thread nasluch = new Thread(new ThreadStart(Nasłuchiwanie));
/*========================================================================================================================*/
//Ustawianie informacji dla okna
public static void SprawdzanieWlasciwosci()
{
// Ustawianie parametrów
Console.SetWindowSize(50, 15);
Console.SetBufferSize(50, 15);
}
//Ustawienia w AppData
public static void F_AppData()
{
if (!Directory.Exists(Appdata)) Directory.CreateDirectory(Appdata);
if (!File.Exists(FileAppdata)) { File.Create(FileAppdata); System.IO.File.WriteAllText(FileAppdata, "FilePath = "); }
}
//Poprawka do 'center', Wyrównywanie tekstu do środka
public static void a(int tablica)
{
if (tablica > 0 && tablica < 4)
{
Console.SetCursorPosition(PoprawkaDoSzerokości, odliczanie);
}
}
// Odczyt pliku | Narazie testy
public static ArrayList zapis_odczyt (int tryb)
{
if (tryb == 1)
{
SW = new StreamWriter(PATH);
SR = new StreamReader(PATH);
while (TEMP != null)
{
TEMP = SR.ReadLine();
if (TEMP != null)
tekst.Add(TEMP);
}
return tekst;
}
else return null;
}
//Logika menu
public static void Nasłuchiwanie() //Brak pełnej implementacji działania na plikach
{
for (;;)
{
string[] options = { "Ścieżka do pliku tekstowego : "+PATH+"\n(F1 - Zmiana ścieżki, F2 - usunięcie ścieżki)", "Wyjście (F3)" };
//for_Nas = false;
if ((GetKeyState(VirtualKeys.Keyboard_1) & 0x80) == 0x80 || (GetKeyState(VirtualKeys.NumPad_1) & 0x80) == 0x80)
{
if (true){Console.WriteLine("Nie zapisałeś ustawień, wybierz opcję \' 3 \'"); Thread.Sleep(2000); Console.Clear(); Draw();
}
}
else if ((GetKeyState(VirtualKeys.Keyboard_2) & 0x80) == 0x80 || (GetKeyState(VirtualKeys.NumPad_2) & 0x80) == 0x80)
{
if (true) { Console.WriteLine("Nie zapisałeś ustawień, wybierz opcję \' 3 \'"); Thread.Sleep(2000); Console.Clear(); Draw(); zapis_odczyt(1); }
}
if ((GetKeyState(VirtualKeys.Keyboard_F1) & 0x80) == 0x80 && for_Nas)
{
Console.Clear(); Draw(); Console.WriteLine("Wprowadź nową ścieżkę : "); PATH = Console.ReadLine(); Console.Clear(); for_Nas = false; Draw();
}
else if ((GetKeyState(VirtualKeys.Keyboard_F2) & 0x80) == 0x80 && for_Nas)
{
Console.Clear(); Draw(); for_Nas = false; // Niedokończone
}
else if ((GetKeyState(VirtualKeys.Keyboard_F3) & 0x80) == 0x80 && for_Nas)
{
Console.Clear(); Draw(); for_Nas = false;
}
if ((GetKeyState(VirtualKeys.Keyboard_3) & 0x80) == 0x80 || (GetKeyState(VirtualKeys.NumPad_3) & 0x80) == 0x80)
{
for (int temp = 0; temp < options.Length; temp++)
{ Console.WriteLine(options[temp]); }
for_Nas = true;
Thread.Sleep(2000);
}
}
}
//Rysunek Menu
public static void Draw()
{
odliczanie = 0;
for (int odliczanieTablicy = 0; odliczanieTablicy < menu.Length; odliczanieTablicy++, odliczanie++)
{
a(odliczanieTablicy); Console.WriteLine(menu[odliczanieTablicy]);
Thread.Sleep(500);
Console.Beep();
}
}
public static void Main()
{
F_AppData();
if (File.Exists(FileAppdata))
{
AppR = new StreamReader(FileAppdata);
string temp1 = AppR.ReadLine();
try { PATH = temp1.Substring(10); }
catch (NullReferenceException) { System.IO.File.WriteAllText(PATH, "FilePath = "); }
}
Console.Clear();
zapis_odczyt(0);
spr_wla.Start();
draw.Start();
nasluch.Start();
odliczanie = 0;
}
}
}
Oraz VirtualKeys.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Szyfrowanie
{
public static class VirtualKeys
{
public const int VK_UP = 0x26;
public const int VK_DOWN = 0x28;
public const int Keyboard_1 = 0x31;
public const int Keyboard_2 = 0x32;
public const int Keyboard_3 = 0x33;
public const int Keyboard_F1 = 0x70;
public const int Keyboard_F2 = 0x71;
public const int Keyboard_F3 = 0x72;
public const int NumPad_1 = 0x61;
public const int NumPad_2 = 0x62;
public const int NumPad_3 = 0x63;
}
}
- Szyfrowanie.rar (2 KB) - ściągnięć: 118