Imports System.IO
Imports System.Windows.Forms

Namespace UTSModule
    Public Class UtsPath

#Region "起始路径"
        ''' <summary>系统文件夹枚举值</summary>
        Public Enum SystemFolderEnum
            ''' <summary>错误记录文件夹</summary>
            Log

            ''' <summary>设置文件夹</summary>
            Setting

            ''' <summary>用户临时操作文件夹</summary>
            Temp
        End Enum


        ''' <summary>
        ''' Temp文件夹下文件夹
        ''' </summary>
        Public Enum SystemTempFolderEnum
            ''' <summary>创建项目时使用文件夹</summary>
            ProjectDesign

            ''' <summary>设计时使用文件夹</summary>
            StationDesign

            ''' <summary>测试时使用文件夹</summary>
            StationTest
        End Enum

        ''' <summary>
        ''' Temp文件夹下文件夹
        ''' </summary>
        Public Enum SystemProductImageFolderEnum
            ''' <summary>产品原图文件夹名</summary>
            MasterImg

            ''' <summary>产品预览图文件夹名</summary>
            PreviewImg
        End Enum


        ''' <summary>
        ''' 本地缓存数据路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property SystemDirPath() As String = Application.StartupPath

        ''' <summary>
        ''' 厂商名
        ''' </summary>
        Public Shared Property VendorName As String


        ''' <summary>
        ''' 校验程序所需的所有文件夹是否存在，不存在则创建
        ''' </summary>
        Public Shared Sub CheckDirectory()
            For Each dirName As String In [Enum].GetNames(GetType(SystemFolderEnum))
                Dim dirPath As String = $"{SystemDirPath}\{dirName}"
                If Directory.Exists(dirPath) = False Then
                    Directory.CreateDirectory(dirPath)
                End If
            Next

            For Each dirName As String In [Enum].GetNames(GetType(SystemTempFolderEnum))
                Dim dirPath As String = $"{TempDirPath()}\{dirName}"
                If Directory.Exists(dirPath) = False Then
                    Directory.CreateDirectory(dirPath)
                End If
            Next


            For Each dirName As String In [Enum].GetNames(GetType(SystemProductImageFolderEnum))
                Dim dirPath As String = $"{StationReleaseDirPath()}\{dirName}"
                If Directory.Exists(dirPath) = False Then
                    Directory.CreateDirectory(dirPath)
                End If
            Next
        End Sub
#End Region


#Region "用户设置相关路径"
        ''' <summary>
        ''' 用户设置文件夹完整路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function SettingDirPath() As String
            Return $"{SystemDirPath}\{SystemFolderEnum.Setting}"
        End Function

        ''' <summary>
        ''' 行节点风格存储文件完整路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function NodeStylePath() As String
            Return $"{SettingDirPath()}\RowNodeStyle.xml"
        End Function
#End Region


#Region "用户日志相关路径"
        ''' <summary>
        ''' 用户日志文件夹完整路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function LogDirPath() As String
            Return $"{SystemDirPath}\{SystemFolderEnum.Log}"
        End Function
#End Region


#Region "项目发布路径"


        ''' <summary>
        ''' 项目站发布文件夹路径,与项目测试站包发布路径区分,可修改
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property StationReleaseDirPath() As String = $"{UtsRegistry.ProductDirPath}"

        ''' <summary>
        ''' 项目站包远程存储路径
        ''' </summary>
        ''' <param name="pid">产品索引</param>
        ''' <param name="sid">产品工艺站索引</param>
        ''' <param name="packetName">产品测试站包名</param>
        ''' <returns></returns>
        Public Shared Function RemoteStationPacketPath(pid As Integer, sid As Integer, packetName As String) As String
            Return $"/uts_Manager/AUTS/{VendorName}/Project/{pid}/{sid}/{packetName}"
        End Function

        ''' <summary>
        ''' 产品原图远程存储路径
        ''' </summary>
        ''' <param name="fileName">产品图像名,含后缀</param>
        ''' <returns></returns>
        Public Shared Function RemoteProductMasterImagePath(fileName As String) As String
            Return $"/uts_Manager/AUTS/{VendorName}/Product/{SystemProductImageFolderEnum.MasterImg}/{fileName}"
        End Function

        ''' <summary>
        ''' 产品预览图远程存储路径
        ''' </summary>
        ''' <param name="fileName">产品图像名,含后缀</param>
        ''' <returns></returns>
        Public Shared Function RemoteProductPreviewImagePath(fileName As String) As String
            Return $"/uts_Manager/AUTS/{VendorName}/Product/{SystemProductImageFolderEnum.PreviewImg}/{fileName}"
        End Function


        ''' <summary>
        ''' 产品原图本地存储文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function ProductMasterImageDirPath() As String
            Return $"{StationReleaseDirPath()}\{SystemProductImageFolderEnum.MasterImg}"
        End Function

        ''' <summary>
        ''' 产品预览图远程存储文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function ProductPreviewImageDirPath() As String
            Return $"{StationReleaseDirPath()}\{SystemProductImageFolderEnum.PreviewImg}"
        End Function

        ''' <summary>
        ''' 产品原图本地存储路径
        ''' </summary>
        ''' <param name="fileName">产品图像名,含后缀</param>
        ''' <returns></returns>
        Public Shared Function ProductMasterImagePath(fileName As String) As String
            Return $"{ProductMasterImageDirPath()}\{fileName}"
        End Function

        ''' <summary>
        ''' 产品预览图远程存储路径
        ''' </summary>
        ''' <param name="fileName">产品图像名,含后缀</param>
        ''' <returns></returns>
        Public Shared Function ProductPreviewImagePath(fileName As String) As String
            Return $"{ProductPreviewImageDirPath()}\{fileName}"
        End Function


        ''' <summary>
        ''' 项目站发布文件夹指定项目名路径
        ''' </summary>
        ''' <param name="pid">产品索引</param>
        ''' <returns></returns>
        Public Shared Function StationProjectReleaseDirPath(pid As Integer) As String
            Return $"{StationReleaseDirPath()}\{pid}"
        End Function


        ''' <summary>
        ''' 项目站包发布路径
        ''' </summary>
        ''' <param name="pid">产品名称</param>
        ''' <param name="sid">站位索引</param>
        ''' <returns></returns>
        Public Shared Function StationPacketReleaseDirPath(pid As Integer, sid As Integer) As String
            Return $"{StationProjectReleaseDirPath(pid)}\{sid}"
        End Function


        ''' <summary>
        ''' 项目站包文件路径
        ''' </summary>
        ''' <param name="pid">产品索引</param>
        ''' <param name="sid">站位索引</param>
        ''' <param name="packetName">包名待.uts后缀</param>
        ''' <returns></returns>
        Public Shared Function StationPacketPath(pid As Integer, sid As Integer, packetName As String) As String
            Return $"{StationPacketReleaseDirPath(pid, sid)}\{packetName}"
        End Function

#End Region


#Region "项目临时编辑文件夹路径"
        ''' <summary>
        ''' 项目临时编辑文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function TempDirPath() As String
            Return $"{SystemDirPath}\{SystemFolderEnum.Temp}"
        End Function

        ''' <summary>
        ''' 临时项目设计文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function ProjectDesignDirPath() As String
            Return $"{TempDirPath()}\{SystemTempFolderEnum.ProjectDesign}"
        End Function

        ''' <summary>
        ''' 临时项目文件路径
        ''' </summary>
        ''' <param name="projectId"></param>
        ''' <returns></returns>
        Public Shared Function ProjectFilePath(projectId As String) As String
            Return $"{ProjectDesignDirPath()}\{projectId}\{projectId}.xml"
        End Function


        ''' <summary>
        ''' 项目站设计文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function StationDesignDirPath() As String
            Return $"{TempDirPath()}\{SystemTempFolderEnum.StationDesign}"
        End Function


#Region "项目站包路径"
        Public Enum PacketDirEnum
            Resource
            TestPlan
        End Enum

        ''' <summary>
        ''' 项目站包信息文件名
        ''' </summary>
        Public Shared StationPacketInfoFileName As String = $"StationInfo.xml"

        ''' <summary>
        ''' 获取指定包名的项目站包文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Function GetStationPacketDirPath(packetName As String) As String
            Return $"{StationDesignDirPath()}\{packetName}"
        End Function

        ''' <summary>
        ''' 获取指定包名的项目站包信息文件路径
        ''' </summary>
        ''' <param name="packetName"></param>
        ''' <returns></returns>
        Public Shared Function GetStationPacketInfoPath(packetName As String) As String
            Return $"{GetStationPacketDirPath(packetName)}\{StationPacketInfoFileName}"
        End Function


        ''' <summary>
        ''' 获取指定包名的项目站包资源文件夹
        ''' </summary>
        ''' <param name="packetName"></param>
        ''' <returns></returns>
        Public Shared Function GetStationPacketResourceDirPath(packetName As String) As String
            Return $"{GetStationPacketDirPath(packetName)}\{PacketDirEnum.Resource}"
        End Function




        ''' <summary>
        ''' 获取指定包名的项目站包测试流程文件夹
        ''' </summary>
        ''' <param name="packetName"></param>
        ''' <returns></returns>
        Public Shared Function GetStationPacketTestPlanDirPath(packetName As String) As String
            Return $"{GetStationPacketDirPath(packetName)}\{PacketDirEnum.TestPlan}"
        End Function


        ''' <summary>
        ''' 项目站包文件夹路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property StationPacketDirPath() As String


        ''' <summary>
        ''' 项目站包信息文件路径
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property StationPacketInfoPath() As String


        ''' <summary>
        ''' 项目站包资源文件夹
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property StationPacketResourceDirPath() As String

        ''' <summary>
        ''' 项目站包资源文件夹
        ''' </summary>
        ''' <returns></returns>
        Public Shared Property StationPacketTestPlanDirPath() As String
#End Region
#End Region


    End Class
End Namespace