using System;
using System.IO;
using System.Windows.Forms;

namespace DebugToolInstrumentInterface;

public static class GeneralHandle
{
	public static string NO_NI_GPIB_SUPPORT_STATEMENT = "NI GPIB is no longer supported by default.  Please download the source code from Createpoint and recompile to support NI GPIB.";

	public static byte[] TrimWithFirstNonZero(byte[] originArray)
	{
		byte[] array = null;
		int num = 0;
		for (int i = 0; i < originArray.Length; i++)
		{
			if (originArray[i] == 0)
			{
				num = i;
				break;
			}
		}
		if (num > 0)
		{
			array = new byte[num];
			for (int j = 0; j < num; j++)
			{
				array[j] = originArray[j];
			}
		}
		return array;
	}

	public static void BatchAssignValue(byte[] arr, byte value)
	{
		int num = arr.Length;
		if (num > 0)
		{
			for (int i = 0; i < num; i++)
			{
				arr[i] = value;
			}
		}
	}

	public static TEDriverType getDriverType(string str)
	{
		if (str == TEDriverType.visa32.ToString())
		{
			return TEDriverType.visa32;
		}
		MessageBox.Show(NO_NI_GPIB_SUPPORT_STATEMENT, "QFDT", MessageBoxButtons.OK, MessageBoxIcon.Hand);
		return TEDriverType.gpib_32;
	}

	public static void writeDebugLog(string strlog)
	{
		string text = "C:\\" + DateTime.Now.ToString("yyyyMM");
		string text2 = "QFDT_Log_" + DateTime.Now.ToString("dd") + ".log";
		text2 = text + "\\" + text2;
		if (!Directory.Exists(text))
		{
			Directory.CreateDirectory(text);
		}
		FileStream fileStream = ((!File.Exists(text2)) ? new FileStream(text2, FileMode.Create, FileAccess.Write) : new FileStream(text2, FileMode.Append, FileAccess.Write));
		StreamWriter streamWriter = new StreamWriter(fileStream);
		streamWriter.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "  ---   " + strlog);
		streamWriter.Close();
		fileStream.Close();
	}
}
