Adds selected script to specified library file
| 15822 | |
| 15823 | // Adds selected script to specified library file |
| 15824 | bool CDallasMainDlg::ExportScriptToFile(char *filename, char *script_name) { |
| 15825 | CFILE *infile; |
| 15826 | char linebuf[2048]; |
| 15827 | char *line; |
| 15828 | int linenum; |
| 15829 | int valid_lines_read; |
| 15830 | HTREEITEM selected_node, script_header_node; |
| 15831 | bool ReplacingScript; |
| 15832 | bool ScriptReplaced; |
| 15833 | |
| 15834 | CurrentParsingFilename = filename; |
| 15835 | |
| 15836 | // Make sure the selected item is valid for exporting |
| 15837 | selected_node = m_ScriptTree.GetSelectedItem(); |
| 15838 | if (selected_node == NULL) |
| 15839 | return FALSE; |
| 15840 | script_header_node = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE); |
| 15841 | if (script_header_node == NULL) |
| 15842 | return FALSE; |
| 15843 | |
| 15844 | // Make sure library file can be written to |
| 15845 | if (_access(filename, 0) != -1) { |
| 15846 | if ((_access(filename, 2)) == -1) { |
| 15847 | CString msg; |
| 15848 | msg.Format("The library file \"%s\" is read-only!", filename); |
| 15849 | MessageBox(msg, "Script Library File Not Writeable!", MB_OK | MB_ICONEXCLAMATION); |
| 15850 | return FALSE; |
| 15851 | } |
| 15852 | } |
| 15853 | |
| 15854 | // Try to open the file for reading |
| 15855 | infile = cfopen(filename, "rt"); |
| 15856 | |
| 15857 | // Try to open the temp file for writing |
| 15858 | CurrentOutputFile = cfopen(TEMP_EXPORT_FNAME, "wt"); |
| 15859 | if (CurrentOutputFile == NULL) { |
| 15860 | CString msg, title; |
| 15861 | msg.Format("ERROR: Unable to open %s for output.", TEMP_EXPORT_FNAME); |
| 15862 | title.Format("Temp File Save Error!"); |
| 15863 | MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION); |
| 15864 | if (infile != NULL) |
| 15865 | cfclose(infile); |
| 15866 | return FALSE; |
| 15867 | } |
| 15868 | |
| 15869 | // If file doesn't exist, Write out the header info |
| 15870 | if (infile == NULL) { |
| 15871 | O(("/////////////////////////////////////////////////////////////////////")); |
| 15872 | O(("// D.A.L.L.A.S. Generated Script Library File ")); |
| 15873 | O(("/////////////////////////////////////////////////////////////////////")); |
| 15874 | O((" ")); |
| 15875 | } |
| 15876 | |
| 15877 | linenum = 0; |
| 15878 | ReplacingScript = FALSE; |
| 15879 | ScriptReplaced = FALSE; |
| 15880 | |
| 15881 | // Read in and parse each line of the file |
nothing calls this directly
no test coverage detected