Skip to content

Commit

Permalink
Conversione di progetto KR Livio : MOD_UTILS_SO
Browse files Browse the repository at this point in the history
- Sostituizione delle chiamate alle WINAPI perchè non riesco a farle funzionare
  Test e funzionamento corretto di ListaFileEDirs e SalvaListaFile
  • Loading branch information
Livio74 committed Dec 23, 2021
1 parent d02826c commit 55a440e
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion KRTest/KRTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="UnitTest1.cs" />
<Compile Include="UnitTestModUtilsSo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
27 changes: 0 additions & 27 deletions KRTest/UnitTest1.cs

This file was deleted.

41 changes: 41 additions & 0 deletions KRTest/UnitTestModUtilsSo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KR.NET;
using System.IO;

namespace KRTest
{
[TestClass]
public class UnitTestModUtilsSo
{
[TestMethod]
public void TestMethodListaFileEDirs()
{
string strDirBase = "D:\\Root\\Working\\Kudalpt2019\\KRTest";
string[] strListFD = new string[5000]; int intNumLV1 = 0;
MOD_UTILS_SO.ListaFileEDirs(strDirBase, strListFD, out intNumLV1);
Console.Out.WriteLine("Inizio Dir List : " + strDirBase);
Assert.AreEqual(2 , intNumLV1);
Assert.AreEqual("Crypt" , strListFD[0]);
Assert.AreEqual("Varie.txt" , strListFD[1]);
for (int i = 0; i < intNumLV1; i++)
{
Console.Out.WriteLine(strListFD[i]);
}
Console.Out.WriteLine("Fine Dir List : " + strDirBase);

}

[TestMethod]
public void TestMethodSalvaListaFile()
{
string DirBase = "D:\\Root\\Working\\Kudalpt2019\\KRTest\\";
string FileOut = DirBase + "out.txt";
string FileOutCfr = DirBase + "outCfr.txt";
MOD_UTILS_SO.SalvaListaFile(FileOut, DirBase + "Crypt\\", "", "klog.txt");
string FileOutString = File.ReadAllText(FileOut);
string FileOutCfrString = File.ReadAllText(FileOutCfr);
Assert.AreEqual(FileOutCfrString, FileOutString);
}
}
}
Binary file modified KRTest/bin/Debug/KR.NET.exe
Binary file not shown.
Binary file modified KRTest/bin/Debug/KR.NET.pdb
Binary file not shown.
Binary file modified KRTest/bin/Debug/KRTest.dll
Binary file not shown.
Binary file modified KRTest/bin/Debug/KRTest.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion KRTest/obj/Debug/KRTest.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
182cd823a95d2aa661c9c72da4f72760d01df655
0b8babe27e9d5eb89a2158c0abc38786f78465fd
Binary file modified KRTest/obj/Debug/KRTest.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified KRTest/obj/Debug/KRTest.dll
Binary file not shown.
Binary file modified KRTest/obj/Debug/KRTest.pdb
Binary file not shown.
45 changes: 11 additions & 34 deletions MOD_UTILS_SO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using System.Reflection;
using System.IO;
using System.Collections.Generic;

// Conversione VB6 to C# di "D:\Root\Computername\Kudapc\e\DOCUMENTI\myPrograms\Visual Basic 6\Kripter\UTILS_SO.bas"
// Ad eccezione di
Expand Down Expand Up @@ -53,18 +54,12 @@ struct SYSTEMTIME
public int wMillisecs;
}

[DllImport("kernel32.dll")]
static extern IntPtr FindFirstFile(IntPtr lpfilename, ref WIN32_FIND_DATA findfiledata);

[DllImport("kernel32.dll")]
static extern IntPtr FindClose(IntPtr pff);

[DllImport("kernel32.dll")]
static extern IntPtr GetLastError();

[DllImport("kernel32.dll")]
static extern IntPtr FindNextFile(IntPtr hFindFile, ref WIN32_FIND_DATA lpFindFileData);

[DllImport("kernel32.dll")]
static extern IntPtr SetFileTime(IntPtr hFile, IntPtr MullP, FILETIME lpLastWriteTime);

Expand All @@ -89,40 +84,22 @@ public static extern IntPtr CreateFileA(

public static void ListaFileEDirs(string strDir , string[] strLista , out int intNum)
{
WIN32_FIND_DATA lpDett = new WIN32_FIND_DATA(); IntPtr hSearch, hNext, lngLastErr;
Boolean bolTrovatoFile = true; string strFile = "";
intNum = 0;
string lpFileNameString = @"\\?\" + strDir + @"\*";
lpFileNameString = @"\\?\" + strDir;

IntPtr lpFileName = Marshal.StringToHGlobalAuto(lpFileNameString);

hSearch = FindFirstFile(lpFileName, ref lpDett);
//Correzione BUG che non c'era
Int32 hSearchValue = hSearch.ToInt32();
if (hSearchValue < 0)
string strDirWithSlash = strDir;
if (strDirWithSlash[strDirWithSlash.Length - 1] != '\\')
{
bolTrovatoFile = false;

} else if (hSearch == IntPtr.Zero)
{
bolTrovatoFile = false;
strDirWithSlash += '\\';
}
//Fine correzione
if (bolTrovatoFile)
{
while (bolTrovatoFile)
IEnumerable<String> fileDirList = Directory.GetFileSystemEntries(strDir, "*.*", SearchOption.TopDirectoryOnly);
foreach(String fileDirItem in fileDirList) {
if (fileDirItem.IndexOf(strDirWithSlash) == 0)
{
strFile = lpDett.cFileName;
strLista[intNum] = fileDirItem.Substring(strDirWithSlash.Length);
intNum = intNum + 1;
strLista[intNum] = strFile;
hNext = FindNextFile(hSearch, ref lpDett);
if (hNext == IntPtr.Zero)
{
bolTrovatoFile = false;
}
} else
{
throw new Exception("File/Dir " + fileDirItem + " not contain base dir " + strDir);
}
FindClose(hSearch);
}
}

Expand Down
Binary file modified bin/Debug/KR.NET.exe
Binary file not shown.
Binary file modified bin/Debug/KR.NET.pdb
Binary file not shown.
Binary file modified obj/Debug/KR.NET.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/KR.NET.exe
Binary file not shown.
Binary file modified obj/Debug/KR.NET.pdb
Binary file not shown.

0 comments on commit 55a440e

Please sign in to comment.