Datei kann nicht gespeichert werden



  • gibts zu tinyxml ne online-doku?
    wenn ja, poste doch ma den link...

    bb





  • Eine andere Möglichkeit wäre, die Datei zuvor zu löschen, aber wie mach ich das? Ich bräuchte eine Funktion die das Löschen erzwingt



  • [MOP] schrieb:

    Eine andere Möglichkeit wäre, die Datei zuvor zu löschen, aber wie mach ich das? Ich bräuchte eine Funktion die das Löschen erzwingt

    Wenn die Datei gelockt ist wird sie sich auch nicht löschen lassen...
    Verwendest du denn auch diese geposteten Funktionen? Es gibt ja ein LoadFile noch mit nem FILE* als Parameter...



  • Ja ich verwende sie immer so:

    TiXmlDocument doc(file.c_str());
    if (!doc.LoadFile())
        {...}
    
    ....
    

    Bin echt am verzweifeln 😮



  • In dieser Funktion wird tatsächlich kein close ausgeführt (zumindest seh ich keinen), soll ich, kann ich da noch was hinzufügen?

    bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding )
    {
    	if ( !file ) 
    	{
    		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
    		return false;
    	}
    
    	// Delete the existing data:
    	Clear();
    	location.Clear();
    
    	// Get the file size, so we can pre-allocate the string. HUGE speed impact.
    	long length = 0;
    	fseek( file, 0, SEEK_END );
    	length = ftell( file );
    	fseek( file, 0, SEEK_SET );
    
    	// Strange case, but good to handle up front.
    	if ( length <= 0 )
    	{
    		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
    		return false;
    	}
    
    	// If we have a file, assume it is all one big XML file, and read it in.
    	// The document parser may decide the document ends sooner than the entire file, however.
    	TIXML_STRING data;
    	data.reserve( length );
    
    	// Subtle bug here. TinyXml did use fgets. But from the XML spec:
    	// 2.11 End-of-Line Handling
    	// <snip>
    	// <quote>
    	// ...the XML processor MUST behave as if it normalized all line breaks in external 
    	// parsed entities (including the document entity) on input, before parsing, by translating 
    	// both the two-character sequence #xD #xA and any #xD that is not followed by #xA to 
    	// a single #xA character.
    	// </quote>
    	//
    	// It is not clear fgets does that, and certainly isn't clear it works cross platform. 
    	// Generally, you expect fgets to translate from the convention of the OS to the c/unix
    	// convention, and not work generally.
    
    	/*
    	while( fgets( buf, sizeof(buf), file ) )
    	{
    		data += buf;
    	}
    	*/
    
    	char* buf = new char[ length+1 ];
    	buf[0] = 0;
    
    	if ( fread( buf, length, 1, file ) != 1 ) {
    		delete [] buf;
    		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
    		return false;
    	}
    
    	const char* lastPos = buf;
    	const char* p = buf;
    
    	buf[length] = 0;
    	while( *p ) {
    		assert( p < (buf+length) );
    		if ( *p == 0xa ) {
    			// Newline character. No special rules for this. Append all the characters
    			// since the last string, and include the newline.
    			data.append( lastPos, (p-lastPos+1) );	// append, include the newline
    			++p;									// move past the newline
    			lastPos = p;							// and point to the new buffer (may be 0)
    			assert( p <= (buf+length) );
    		}
    		else if ( *p == 0xd ) {
    			// Carriage return. Append what we have so far, then
    			// handle moving forward in the buffer.
    			if ( (p-lastPos) > 0 ) {
    				data.append( lastPos, p-lastPos );	// do not add the CR
    			}
    			data += (char)0xa;						// a proper newline
    
    			if ( *(p+1) == 0xa ) {
    				// Carriage return - new line sequence
    				p += 2;
    				lastPos = p;
    				assert( p <= (buf+length) );
    			}
    			else {
    				// it was followed by something else...that is presumably characters again.
    				++p;
    				lastPos = p;
    				assert( p <= (buf+length) );
    			}
    		}
    		else {
    			++p;
    		}
    	}
    	// Handle any left over characters.
    	if ( p-lastPos ) {
    		data.append( lastPos, p-lastPos );
    	}		
    	delete [] buf;
    	buf = 0;
    
    	Parse( data.c_str(), 0, encoding );
    
    	if (  Error() )
            return false;
        else
    		return true;
    }
    


  • Ideen?? 😞



  • Hmmm - für mich sieht es auch so aus, als ob direkt nach dem Laden die Datei wieder geschlossen werden würde (abgesehen von der FILE* überladung, aber das spielt hier auch keine Rolle).

    Was ist, wenn du nen neues Projekt erstellst usw und dann einfach mal nur eine Datei mit lädst und sie direkt danach versuchst, wieder zu löschen/ändern/...?

    Ich glaube nämlich nicht, dass da der Fehler darin liegt...

    bb



  • [MOP] schrieb:

    Noch seltsamer ist, dass das gleiche Programm unter Linux keine Fehler macht...

    Das liegt aber nicht an deinem Programm sondern an Linux 😉 Das lockt keine Files. Wenn Files gelockt werden sollen muss das der Programmierer selber machen. Es ist einfach auf Dateisystemebene kein Lockmechanismus eingebaut.
    Das hat mich zu Windowszeiten (als einfacher, noobiger User) oftmals um den Verstand gebracht.



  • wie gesagt: minimales kompilierbares bsp. posten - vll hat ja jmd tinyxml oder macht sich die mühe, es runterzuladen...
    oder vll erledigt sich dein fehler dann von ganz allein...

    ob das mit den files nicht locken nun vor- oder nachteil ist sei mal dahingestellt...
    [flame gelöscht]
    bb



  • Daß ihr mir immer so viel Arbeit machen müßt... 😞
    Ich lösch dann mal ein paar Postings mit Betriebsystemgeflame.



  • Tut mir leid 🙄 Das hat mich gerade etwas aufgeregt... aber es ist nicht die erste schlechte Erfahrung mit Windows, die ich gemacht habe (ich hoffe das ist noch erlaubt zu sagen)



  • Sry Windows, sry Microsoft, diesmal war es echt mein Fehler: 🙄

    std::ifstream filetester;
    filetester.open(secarg.c_str());
                if (filetester.is_open()!=true)
                {
                    std::cout << "Konnte nicht öffen: "<<secarg<<"\n";
                    return 0;
                }
    

    Und was hab ich vergessen? xD



  • eigtl nix, wenn du es mal in ne fkt. gepackt hättest - aber das hast du offenbar nicht...

    btw:

    std::ifstream filetester(secarg.c_str());
    if (!filetester.is_open())
    {
      std::cout << "Konnte nicht öffen: "<<secarg<<"\n";
      return 0;
    }
    

    und dort "\n" zu schreiben... ich weiß nicht, wenn schon nicht std::endl(dort spricht ja nun echt nix dagegen), dann vll '\n'...

    das wiederrum kann man jz in ne voll tolle fkt. packen:

    bool file_exist(const char* filename)
    {
      std::istream file(filename);
      return file.is_open();
    }
    
    int main()
    {
      /*...*/
      std::string file;
      /*...*/
      if(!file_exist(file.c_str()))
      {
        std::cout << "x" << file << std::endl;
        return -1;
      }
    }
    

    und wenn man irgendwann mal langeweile hat, kann man die fkt evtl noch anders implementieren(wird sicherlich was schnelleres geben, wenn man nur wissen will, ob die datei existiert).

    bb


Anmelden zum Antworten