using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Lococo
{
public partial class MainForm : MetroFramework.Forms.MetroForm
{
#region Windows API
[DllImport("user32")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr FindWindowEx(IntPtr parentHWnd, IntPtr childAfterHWnd, string className, string windowTitle);
[DllImport("user32")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(IntPtr hWnd);
#endregion
#region Global Variables
private Forms.overlayForm overlayForm = new Forms.overlayForm();
private Forms.messageForm messageForm;
private readonly string appPath = Application.StartupPath;
private readonly string app_version = "2021-05-18";
#endregion
/*
private void loadContinents()
{
string filePath = appPath + "dbmapslist.ini";
byte continent_count = 0;
continent.Items.Clear();
continent.Items.Add(">> 대항해");
using (var configClass = new Functions.manageConfig())
{
Byte.TryParse(configClass.readConfig("Continent", "Count", filePath), out continent_count);
for (byte index=1; index<continent_count; ++index)
{
continent.Items.Add(configClass.readConfig("Continent List", index.ToString(), filePath));
}
}
}
private void loadAreas()
{
string filePath = appPath + "dbmapscontinents";
byte area_count = 0, dungeon_count = 0;
area.Items.Clear();
if (continent.SelectedIndex == 0)
{ }
else
{
filePath += continent.SelectedIndex.ToString() + "list.ini";
using (var configClass = new Functions.manageConfig())
{
byte.TryParse(configClass.readConfig("Area", "Count", filePath), out area_count);
byte.TryParse(configClass.readConfig("Dungeon", "Count", filePath), out dungeon_count);
for (byte index=1; index<area_count+1; ++index)
{
area.Items.Add(configClass.readConfig("Area List", index.ToString(), filePath));
}
if (dungeon_count > 0)
{
area.Items.Add("");
for (byte index=1; index<dungeon_count+1; ++index)
{
area.Items.Add(">> " + configClass.readConfig("Dungeon List", index.ToString(), filePath));
}
}
}
}
}
*/
#region App Functions
private void preventDoubleExcuting()
{
Process[] proc1 = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
if (proc1.Length > 1)
{
for (byte index = 0; index < proc1.Count(); ++index)
{
if (proc1[index].MainWindowHandle != this.Handle)
SetForegroundWindow(proc1[index].MainWindowHandle);
}
Environment.Exit(0);
}
for (byte index = 0; index < proc1.Length; ++index)
proc1[index].Dispose();
}
private bool customMsgbox(string message, string caption, int width, int height, bool yesNo)
{
bool result = false;
messageForm = new Forms.messageForm();
messageForm.msg = message;
messageForm.cap = caption;
messageForm.width = width;
messageForm.height = height;
messageForm.yesNo = yesNo;
messageForm.ShowDialog();
if (messageForm.dialogResult == 1)
result = true;
messageForm.Dispose();
return result;
}
#endregion
public MainForm()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams crp = base.CreateParams;
crp.ClassStyle = 0x00020000;
return crp;
}
}
#region Event Handlers - Form
private void MainForm_Load(object sender, EventArgs e)
{
preventDoubleExcuting();
File.Open(Application.ExecutablePath, FileMode.Open, FileAccess.Read, FileShare.Read);
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
if (!customMsgbox("프로그램이 정상작동하지 않을 수 있습니다.rnrn프로그램을 실행하실건가요?", "인터넷 연결되지 않음", 500, 250, true))
Environment.Exit(0);
}
else
{
using (var ftp = new Functions.checkVersion())
{
string server_version = ftp.DownloadFTPString("version.ini");
if (server_version != app_version)
{
if (!customMsgbox("프로그램이 최신버전이 아니에요!rnrn그래도 이용하시겠어요?", "최신버전 아님", 400, 250, true))
Environment.Exit(0);
}
}
}
mainTab.SelectedIndex = 0;
this.Size = new Size(850, 650);
}
private void MainForm_Resize(object sender, EventArgs e)
{
int white_space = version_label.Left;
mainTab.Size = new Size(this.Width - (white_space * 2), this.Height - (mainTab.Top + white_space));
}
#endregion
#region Event Handlers - About Map
private void mapToggle_Click(object sender, EventArgs e)
{
if (mapToggle.Checked && !overlayForm.IsHandleCreated)
{
overlayForm = new Forms.overlayForm();
overlayForm.webURL = mapURL.Text;
overlayForm.Opacity = (float)map_Bar.Value / 100;
overlayForm.Show();
overlayForm.setTransparent(map_changeState.Checked);
}
else
{
overlayForm.Dispose();
overlayForm.Close();
}
}
private void mapHelp_Click(object sender, EventArgs e)
{
customMsgbox("이 기능을 활성화하실 경우, 웹 브라우저 부분에 전달되는 키보드/마우스의 명령이 무시되어 다른 프로그램에 전달됩니다.", "입력 무시 도움말", 525, 250, false);
}
private void map_Bar_Scroll(object sender, ScrollEventArgs e)
{
map_BarLB.Text = "불투명도: " + map_Bar.Value.ToString() + "%";
if (overlayForm.IsHandleCreated)
{
overlayForm.Opacity = (float)map_Bar.Value / 100;
}
}
private void map_changeState_Click(object sender, EventArgs e)
{
if (mapToggle.Checked)
{
if (map_changeState.Checked)
overlayForm.setTransparent(true);
else
overlayForm.setTransparent(false);
}
}
private void map_appendURL_Click(object sender, EventArgs e)
{
if (mapToggle.Checked)
{
overlayForm.webURL = mapURL.Text;
overlayForm.navigateBrowser();
}
}
private void map_resetURL_Click(object sender, EventArgs e)
{
mapURL.Text = "https://lostark.inven.co.kr/dataninfo/world/";
if (mapToggle.Checked)
{
overlayForm.webURL = mapURL.Text;
overlayForm.navigateBrowser();
}
}
#endregion
}
}