Como Conversor de txt para csv lendo direto do registro do windows obrigatoriamente?

Delphi

30/04/2015

Tenho o seguinte:
Requirementos
Criar uma aplicação no delphi 7 para converter arquivo de texto(com o conteúdo registro do windows) para o tipo csv.
Se espera esta linha de comando • Regis tryToCsv.exe inputFile outputFile
O arquivo de entrada o inputFile não deve ser importado do registro, mas deve ser lido como ele é. Como se faz no bloco de notas:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Seventh\DGuardCenter\Servidores]
"Count"=dword:0000000c

[HKEY_CURRENT_USER\Software\Seventh\DGuardCenter\Servidores\Servidor00]
"Guid"=hex:1b,0d,fa,95,6c,f4,a0,48,98,94,73,20,d1,d9,a7,cf
"ParentGuid"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
"Nome"="nvr-pc"
"IP"="nvr-pc"
"Porta"=dword:00001b9e
"AutoConectar"=dword:00000001
"Redirecionador"=dword:00000000
"ConexaoInversa"=dword:00000000
"VendorName"="Seventh"
"ModelName"="D-Guard Center"
"IsRemoteBridged"=dword:00000000
"Usuario"="demo"
"Senha"="demo"
"CamerasAnalogicasAtivas"=dword:00000001
"CodigoStr"="A001"
"Particao"="00"
"TimeOut"=dword:0000003c
"StreamsSempreAtivas"=dword:00000000


E a saida, o novo arquivo sera:

Codigo,Nome,Fabricante,Modelo,IP,Porta,Usuario,Senha,Redirecionador,ConexaoInversa
A001,nvr-pc,Seventh,D-Guard Center,nvr-pc,7070,demo,demo,0,0
0001,24-Tecvoz HLC79AD,TecVoz,HLC-79AD/W,192.168.0.24,80,admin,admin,0,0
0001,25-Tecvoz HLV1WAD,TecVoz,HLV-1WAD/P,192.168.0.25,80,admin,admin,0,0
0001,27-Tecvoz IPH-3611 SD,TecVoz,IPH-3611N,192.168.0.27,80,admin,admin,0,0
0001,20-Axis M1031,Axis Communications AB,M1031-W,192.168.0.20,80,admin,admin,0,0
0001,29-Teki,Teki,TK-9522,192.168.0.29,80,admin,admin,0,0
0001,41-Venetian Dome 5Mega,Venetian,Dome 5 MEGA,192.168.0.41,80,root,pass,0,0
0002,30-Zavio F3210,Zavio,F3210,192.168.0.30,80,admin,admin,0,0
0003,31-Zavio D5210,Zavio,B7210,192.168.0.31,80,admin,admin,0,0
0010,28-TecVoz,TecVoz,HLC-79AD/W,192.168.0.28,80,admin,admin,0,0
0008,21-Axis M1104,Axis Communications AB,M1104,192.168.0.21,80,admin,admin,0,0
0005,33-Zavio B7210,Zavio,B7210,192.168.0.33,80,admin,admin,0,0

Primeiro penso em trazer para um Tmemo o conteúdo da chave que procuro.
Depois quero enviar o arquivo já convertido para o excel. Já no formato csv.

Eu tentei isso:

procedure TForm1.btnOpenClick(Sender: TObject);
var
reg: TRegistry;
valores: TStringList;
key: TStringList;
i,j:integer;
nome_valor: string; // Nome do valor
dados_valor: string; // Dados do valor
key_name:string;

begin
FrmResult.Memo1.Lines.Clear;
FrmResult.Memo1.Lines.Add('Windows Registry Editor Version 5.00');
FrmResult.Memo1.Lines.Add('');
reg := TRegistry.Create;
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion',false);
valores := TStringList.Create;
//key := TStringList.Create;
//reg.GetKeyNames(key);
reg.GetValueNames(valores);
Key_name:=(reg.CurrentPath);
frmResult.Memo1.Lines.Add('['+(key_name)+']');
frmResult.Memo1.Lines.Add('');
for i :=0 to valores.Count -1 do
begin
nome_valor := valores.Strings[i];
dados_valor := reg.ReadString(nome_valor);
frmResult.Memo1.Lines.Add('"'+nome_valor+'"'+' = '+'"'+dados_valor+'"');
end;

frmResult.Show;
reg.CloseKey();
reg.free;
end;


Não to conseguindo fazer o meu Memo ficar igual é gerado com o bloco de notas.
mas achei isso:

Windows Registry Editor Version 5.00

[SOFTWARE\Microsoft\Windows\CurrentVersion]

"SM_GamesName" = "Games"
"SM_ConfigureProgramsName" = "Set Program Access and Defaults"
"CommonFilesDir" = "C:\Program Files\Common Files"
"DevicePath" = "%SystemRoot%\inf"
"MediaPathUnexpanded" = "%SystemRoot%\Media"
"ProgramFilesDir" = "C:\Program Files"
"ProgramFilesPath" = "%ProgramFiles%"


Talvez seja melhor eu postar o meu trabalho para entenderem tudinho.(em ingles).

Introduction

This document describes the Seventh Technical Assessment in terms of requirements and deliverables needed to be submitted. You should read it carefully before you begin working on the assessment.
The assessment consists of designing and implementing a "Registry file to CSV file converter".

The assessment is distributed with:
• this document;
• the file "Servidores.txt" as a sample of the input file;
• the file "Servidores.csv" as a sample of the expected output file;

Requirements
You are requested to produce an implementation of this file converter application, respecting the following requirements.
It is required to provide a fully functional console application, capable of converting files in the specified format. The console application should expect the following command line interface:
• RegistryToCsv.exe inputFile outputFile

Functional Requirements
The file converter should convert a file that uses the "registry format", which format is defined by the sample file "Servidores.txt", to a CSV file (comma separated), which format is specified in the sample file "Servidores.csv". The conversion tool should not import the original file to the Windows Registry, the input file must be read as it is.

Other Requirements
The work involves a number of design choices that have to be made. In all such cases, the following principles should be applied.

Clarity and Maintainability
A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient than the simple choice.

Documentation
The code itself should be as clear as possible, and "obvious" comments should be avoided. Awkward or complex code should have descriptive comments.

Correctness
The design used must correctly implement the specified requirements. The converter application must pass the provided test case (converting Servidores.txt into Servidores.csv). Although this is not mandatory, you are free to provide the assessor with more appropriate tests.

Use of Frameworks/Libraries
External frameworks/libraries can be used to solve a part of the problem, provided that the framework/libraries and its dependencies are packaged within the submission.

Decoupling
Design and implementation choices must consider decoupling separate parts of the software whenever possible, to improve the maintainability and reuse of these parts.

State of the Art
The design should use design patterns wherever appropriate. Do not create your own design when well known and proven solution already exists. Best practices should be applied both for the design and for the coding of the solution.

Target Environment
Throughout this assessment, you could use any version of the Delphi IDE - from Delphi 5 to XE6. You are not required to develop your code using any particular version of the Delphi IDE, but the submission that you return must have been tested and shown to work using the version you have chosen.

Duration
The assessment has been designed to require a maximum of 8 hours work.

Execution of Submissions
When you submit your assignment, you must ensure that it is packaged in such a way that it is completely clear how the assessor should run it.

Deliverables
When you submit your assessment, you should provide the following parts:
• Full source code. You may use a ZIP file to contain groups of elements of your submission as you deem appropriate. Dependencies such as external frameworks, if any, must be included into the ZIP file.
* Compiled, functional, console application, named RegistryToCsv.exe.
• A README.txt file that describes to the assessor the exact version of Delphi you used and how to compile/run your application. It should also describes external dependencies, if needed.

What to do if you have a question
You may find that you want to ask for further explanation of some part of these notes, perhaps to seek permission to solve a problem in a particular way. These notes deliberately leave some issues unspecified, and some problems unraised. Your ability to think through these issues, in the face of realistically imperfect specifications, and come to a tenable solution is something upon which you are being graded.
You should consider the options available and make a decision about how to address the problem yourself. This decision making process is part of the marking scheme, and as such it is crucially important that you provide documentation of your choice. Be sure to describe the options you considered, the perceived benefits and weaknesses of each, and why you chose the solution you did. You will not be marked so much on the choice that you made, but rather on the consistency of your decision making process and your adherence to other aspects of these notes during that decision making process.
Fabiano

Fabiano

Curtidas 0
POSTAR