Reading a static file in C++ within the code - visual-studio

I have a code which will read the xml file using pugi xml. Given below is the content of the same.
xml_document doc;
xml_parse_result result = doc.load_file(sXMLFilePath.c_str());
Here sXMLFilePath is the file present in my system. I want to hard-code this file into the code itself. I dont want to read this file from the machine. Meaning I want to make this file static.
Also if the file size is more than 30MB, can I compress the same?

Related

Issue when copying two text files using the copy command

I am having an issue when attempting to copy two files into a separate file using the Windows Copy command. In the first file, when I open the text file in notepad I see the data in the file formatted as expected.
File #1
0900|Y3RN|19944|12/OCT/2016|2|2|1600|C||||||0|0|||Replace
0900|Y3RN|19944|13/OCT/2016|2|2|2000|C||||||0|0|||Replace
0900|Y3RN|19944|14/OCT/2016|2|2|600|C||||||0|0|||Replace
However in the second file that has the same fields the format of the data in notepad is different.
File #2
0901|ECQQ|339489|18/OCT/2016|2|2|25|C||||||0|0|||Replace0901|ECQQ|339489|19/OCT/2016|2|2|180|C||||||0|0|||Replace0901|EK1P|339489|04/OCT/2016|2|2|100|C||||||0|0|||Replace
Supposedly the same process is generating the two files on my customer's system of record. If I open only each file separately using Textpad, the two files have the same format as File#1 above.
When I use the Copy command, the resulting file looks as below when viewing in Notepad.
0900|Y3RN|19944|28/OCT/2016|2|2|1400|C||||||0|0|||Replace
0900|Y3RN|19944|31/OCT/2016|2|2|1400|C||||||0|0|||Replace
0900|Y6CJ|19944|10/OCT/2016|2|2|200|C||||||0|0|||Replace0901|ECQQ|339489|18/OCT/2016|2|2|25|C||||||0|0|||Replace0901|ECQQ|339489|19/OCT/2016|2|2|180|C||||||0|0|||Replace0901|EK1P|339489|04/OCT/2016|2|2|100|C||||||0|0|||Replace
However when viewing the resulting file in Textpad, the format is correct.
There has to be something missing in the format of File#2, but since I do not have access or visibility to how these files are being generated my hands are tied.
Is there a way to convert File #2 so that it is formatted exactly like File#1?

Disallowed types file

It's easy to set the allowed file in code igniter when we want to upload file if the amount is less. But if there are almost extension file I want to set as allowed types of file that can be uploade except file extension of .exe, how the easiest way to set the code ? besides I have to type all of type code in allowed_types configuration. ..

How can I specify filesystem rules?

I have the following two challanges:
I'd like to assert that the filename of an xml file is always equal to a certain string in the file itself
I'd like to assert that in every folder called 'Foo' is a file called 'bar.xml'
How can I do this with sonar? Is there already a plugin for this available?
There's no plugin for that, you will have to write your own.
To do the first point, you can write a sensor that parses the XML files to find if the name of the files exists in the file itself, this should not be complicated.
For the second point, you would have to write a sensor that is executed only on folders.
You can check the "Extension Guide" documentation to find code samples on how to do that.

How to validate that an uploaded file is complete

I have an system with which users can upload a CSV file via an FTP server, or via a html form. On my end, a script polls the uploads directory and processes new files found. Some users will create the CSV by exporting it from Excel, while others will programmatically create it with scripts of their own.
My concern at the moment is: How can I be 100% certain that the file my processing script acts on is complete - in other words that it isn't a partial file (in progress, failed upload, etc)?
If the file format was something more structured, like XML, I'd be 100% confident that the file is complete by checking that the XML structure is valid (ie: closing tags).
Is there a good way to ensure that the uploaded CSV file is complete, without burdening & confusing less technical users who are simply uploading a file exported from a spreadsheet program (ie: providing an md5 of the file contents would be beyond them).
When designing CSV file formats in the past, I've always added a header and footer line as follows:
id,one,two,three,four,five,six
10,1,2,3,4,5,6
11,1,2,3,4,5,6
12,1,2,3,4,5,6
13,1,2,3,4,5,6
14,1,2,3,4,5,6
FOOTER,5
Most CSV file formats have a header to label the columns, the purpose of the footer is to indicate the file is completed. The footer contains a simple line count, which is easy to audit when looping through the file's contents. Not too complicated for users.
You could crosscheck whenever the filesize of the uploaded file matches the filesize of the original file.

XML File missing when we publish the vb.net application as click once

I am having an XML file in the application start up path. The program has to read the xml file. It works fine in the development.but when I publish the Application. The XML file is not copied to the out put directory
I have tried to set the copy to output directory always. but no luck
Have you set the xml file properties to be Content rather than None in visual studio?
It might be better to make it an embedded resource and write it do disk on the target machine if it does not exist, that way users can do a local restore but still edit a local version if required.
Dim read As Stream = Me.GetType().Assembly.GetManifestResourceStream("my-file.xml")
Dim buf() As Byte = New Byte((read.Length) - 1)
Dim file As New FileStream("C:\test.xml", FileMode.Create)
read.Read(buf, 0, buf.Length)
file.Write(buf, 0, buf.Length)
file.Close()
read.close()
disclaimer: It's been a long time since I did VB and I've not tried this code but th egist is there
Also you should consider the file size and maybe read in chunks rather than the whole lot depending on the file size. I've added no error handling and you'll obviously want to see if the file is there first

Resources