Skip to content

Commit

Permalink
添加项目文件。
Browse files Browse the repository at this point in the history
  • Loading branch information
老孙 authored and 老孙 committed Jun 9, 2023
1 parent 27bc720 commit 471b96e
Show file tree
Hide file tree
Showing 18 changed files with 1,335 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# IDE0059: 不需要赋值
dotnet_diagnostic.IDE0059.severity = none
14 changes: 14 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Application x:Class="SchoolNetConnect.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SchoolNetConnect"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinViolet.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace SchoolNetConnect
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
21 changes: 21 additions & 0 deletions GetSystemData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Net;
using System.Net.Sockets;
namespace SchoolNetConnect
{
public class GetSystemData //处理函数之类的
{
public static string GetIP()
{
string localIP = "127.0.0.1";
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
{
socket.Connect("255.255.255.255", 65530);
#pragma warning disable CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
#pragma warning restore CS8600 // 将 null 字面量或可能为 null 的值转换为非 null 类型。
localIP = endPoint!.Address.ToString();
}
return localIP;
}
}
}
121 changes: 121 additions & 0 deletions IniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
using System.Text;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
using System.Windows.Documents;

namespace SchoolNetConnect
{
public class IniFile
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name!;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
public IniFile(string IniPath = null!)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName;
}
public string Read(string Key, string Section = null!)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}
public void Write(string Key, string Value, string Section = null!)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}
public void DeleteKey(string Key, string Section = null!)
{
Write(Key, null!, Section ?? EXE);
}
public void DeleteSection(string Section = null!)
{
Write(null!, null!, Section ?? EXE);
}
public bool KeyExists(string Key, string Section = null!)
{
return Read(Key, Section).Length > 0;
}
/// <summary>
/// 找到当前路径下文件扩展名相同的文件
/// </summary>
/// <param name="path">路径</param>
/// <returns></returns>
public List<string> GetIniFile(string path)
{
// 获取文件夹的文件
DirectoryInfo fdir = new DirectoryInfo(path);
FileInfo[] file = fdir.GetFiles();
List<string> Inilist = new List<string>(500);
if (file.Length > 0)
{
foreach (var f in file)
{
string ext = ".ini";
if (ext.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
{
string fileName = System.IO.Path.GetFileName(f.FullName);
Inilist.Add(fileName);
}
}
}

return Inilist;
}
public void IniFileinit(String OP)
{
if(OP=="Write")
{
Write("username", "", "UserConfig");
Write("password", "", "UserConfig");
Write("ISP", "", "UserConfig");
Write("UseCustomIp", "False", "UserConfig");
Write("CustomIp", "", "UserConfig");
Write("OnConnect", "false", "RunningDate");
Write("SetIP", "false", "UserConfig");
Write("SetReset", "false", "UserConfig");
Write("Resettime", "1", "UserConfig");
Write("Resetcount", "1", "UserConfig");
Write("Driver", "PC", "UserConfig");
Write("AutoRun", "false", "UserConfig");
}


}

public void ConfigRead(IniFile Config,
out string OnConnect,
out string AutoRun,
out string Driver,
out string UserName,
out string Password,
out string CustomIp,
out string Resettime,
out string Resetcount,
out string ISP,
out string SetIP,
out string SetReset,
out string NowIp
)
{
AutoRun = Config.Read("AutoRun", "UserConfig");
Driver = Config.Read("Drivers", "UserConfig");
UserName = Config.Read("username", "UserConfig");
Password = Config.Read("password", "UserConfig");
CustomIp = Config.Read("CustomIp", "UserConfig");
Resettime = Config.Read("Resettime", "UserConfig");
Resetcount = Config.Read("Resetcount", "UserConfig");
ISP = Config.Read("ISP", "UserConfig");
SetIP = Config.Read("SetIP", "UserConfig");
SetReset = Config.Read("SetReset", "UserConfig");
NowIp = GetSystemData.GetIP();
OnConnect = Config.Read("Onconnect", "RunningDate");
}
}
}
Loading

0 comments on commit 471b96e

Please sign in to comment.