У меня следующая проблема: я хочу проверить, содержит ли gameName предопределенные строки, доступные внутри функции, но почему-то он не переносит их обратно.Я действительно не знаю почему, так как они объявлены в функции и должны быть перенесены обратно в основную часть.Кстати, вход для OpenFileDialog1 - это файл с именем: hl1-sp-the-infinite-shift.7z
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.IO;
namespace MapTap2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string CheckGame(string sourceName, string gamename)
{
string hl1 = "hl1";
string hl2 = "hl2";
string hl2ep2 = "hl2-ep2";
string hl2ep1 = "hl2-ep1";
string bs = "bs";
string prtl = "prtl";
string prtl2 = "prtl";
string op = "op";
bool gamebool;
gamebool = sourceName.Contains(hl1);
if (gamebool == true)
{
gamename = "hl1";
return gamename;
}
gamebool = sourceName.Contains(hl2);
if (gamebool == true)
{
gamename = "hl2";
return gamename;
}
gamebool = sourceName.Contains(hl2ep2);
if (gamebool == true)
{
gamename = "hl2-ep2";
return gamename;
}
gamebool = sourceName.Contains(hl2ep1);
if (gamebool == true)
{
gamename = "hl2-ep1";
return gamename;
}
gamebool = sourceName.Contains(bs);
if (gamebool == true)
{
gamename = "bs";
return gamename;
}
gamebool = sourceName.Contains(prtl);
if (gamebool == true)
{
gamename = "prtl";
return gamename;
}
gamebool = sourceName.Contains(prtl2);
if (gamebool == true)
{
gamename = "prtl2";
return gamename;
}
gamebool = sourceName.Contains(op);
if (gamebool == true)
{
gamename = "op";
return gamename;
}
else
{
gamename = "You sure that this file is from PP?";
return gamename;
}
}
private void Form1_Load(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = @"C:\Users\";
openFileDialog1.Filter = "7zip archives|*.7z|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
}
private void cmdCompress_Click(object sender, EventArgs e)
{
string sourceName = "";
string targetFolderName = "testy";
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null )
{
sourceName = openFileDialog1.FileName;
lblconsole.Text = sourceName;
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7za.exe";
p.Arguments = " e " + sourceName + " -o" + targetFolderName;
Process x = Process.Start(p);
x.WaitForExit();
//Check the Game Version of the archive (line 20)
string gamename = "If you see this in Debug you failed.\n Y U NO MAKE WORKING CODE?";
CheckGame(sourceName, gamename);
lblconsole.Text = gamename;
}
}
}
}
}